From a087fb7ffa06324e1574e00bb61061d16d2be112 Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Thu, 27 Jun 2024 01:48:55 +0600 Subject: [PATCH] added 1982D --- .../1982D.cpp | 78 +++++++++++++++++++ Readme.md | 25 +++--- 2 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 Codes/1982 D - Beauty of the mountains/1982D.cpp diff --git a/Codes/1982 D - Beauty of the mountains/1982D.cpp b/Codes/1982 D - Beauty of the mountains/1982D.cpp new file mode 100644 index 0000000..f527fd0 --- /dev/null +++ b/Codes/1982 D - Beauty of the mountains/1982D.cpp @@ -0,0 +1,78 @@ +#include +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define all(x) x.begin(), x.end() +#define sz(x) (int)(x).size() +#define yn(f) f? cout<<"YES\n":cout<<"NO\n" +#define rep(i,a,b) for(int i=a; i=b; --i) +#define pb push_back +#define ppb pop_back +#define ins insert +#define ff first +#define ss second +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7){ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + int n,m,k; + cin>>n>>m>>k; + vector>a(n, vector(m)),pf(n+1,vector(m+1,0)); + for(auto &x:a) + { + for(auto &i:x) cin>>i; + } + vectorb(n); + for(auto &i:b) cin>>i; + int diff=0; + rep(i,0,n) + { + rep(j,0,m) + { + if(b[i][j]=='1') diff += a[i][j]; + else diff -= a[i][j]; + } + } + diff=abs(diff); + rep(i,1,n+1) + { + rep(j,1,m+1) + { + int val=-1; + if(b[i-1][j-1]=='1') val=1; + pf[i][j] = val+pf[i-1][j]+pf[i][j-1]-pf[i-1][j-1]; + } + } + int g=0; + for(int i=1; i<=n-k+1; ++i) + { + for(int j=1; j<=m-k+1; ++j) + { + int val=pf[i+k-1][j+k-1] - pf[i-1][j+k-1] - pf[i+k-1][j-1]+pf[i-1][j-1]; + g = gcd(g,abs(val)); + } + } + if(diff==0) yn(1); + else if(g==0) yn(0); + else yn(diff%g==0); +} + +signed main() +{ + FAST; + int TCS = 1; + cin >> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "<