added 1982D

This commit is contained in:
ShazidMahsrafi 2024-06-27 01:48:55 +06:00
parent 4c15f1f277
commit a087fb7ffa
2 changed files with 91 additions and 12 deletions

View File

@ -0,0 +1,78 @@
#include <bits/stdc++.h>
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 rrep(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<vector<int>>a(n, vector<int>(m)),pf(n+1,vector<int>(m+1,0));
for(auto &x:a)
{
for(auto &i:x) cin>>i;
}
vector<string>b(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 "<<TC<<": ";
solve();
}
}

View File

@ -345,18 +345,19 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 333 | 1982 A | Soccer | [Question](https://codeforces.com/problemset/problem/1982/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1982%20A%20-%20Soccer)
| 334 | 1982 B | Collatz Conjecture | [Question](https://codeforces.com/problemset/problem/1982/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1982%20B%20-%20Collatz%20Conjecture)
| 335 | 1982 C | Boring Day | [Question](https://codeforces.com/problemset/problem/1982/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1982%20C%20-%20Boring%20Day)
| 336 | 1985 A | Creating Words | [Question](https://codeforces.com/problemset/problem/1985/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20A%20-%20Creating%20Words)
| 337 | 1985 B | Maximum Multiple Sum | [Question](https://codeforces.com/problemset/problem/1985/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20B%20-%20Maximum%20Multiple%20Sum)
| 338 | 1985 C | Good Prefixes | [Question](https://codeforces.com/problemset/problem/1985/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20C%20-%20Good%20Prefixes)
| 339 | 1985 D | Manhattan Circle | [Question](https://codeforces.com/problemset/problem/1985/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20D%20-%20Manhattan%20Circle)
| 340 | 1985 E | Secret Box | [Question](https://codeforces.com/problemset/problem/1985/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20E%20-%20Secret%20Box)
| 341 | 1985 F | Final Boss | [Question](https://codeforces.com/problemset/problem/1985/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20F%20-%20Final%20Boss)
| 342 | 1985 G | D-Function | [Question](https://codeforces.com/problemset/problem/1985/G) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20G%20-%20D-Function)
| 343 | 1986 A | X Axis | [Question](https://codeforces.com/problemset/problem/1986/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20A%20-%20X%20Axis)
| 344 | 1986 B | Matrix Stabilization | [Question](https://codeforces.com/problemset/problem/1986/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20B%20-%20Matrix%20Stabilization)
| 345 | 1986 C | Update Queries | [Question](https://codeforces.com/problemset/problem/1986/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20C%20-%20Update%20Queries)
| 346 | 1986 D | Mathematical Problem | [Question](https://codeforces.com/problemset/problem/1986/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20D%20-%20Mathematical%20Problem)
| 347 | 1986 E | Beautiful Array | [Question](https://codeforces.com/problemset/problem/1986/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20E%20-%20Beautiful%20Array)
| 336 | 1982 D | Beauty of the mountains | [Question](https://codeforces.com/problemset/problem/1982/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1982%20D%20-%20Beauty%20of%20the%20mountains)
| 337 | 1985 A | Creating Words | [Question](https://codeforces.com/problemset/problem/1985/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20A%20-%20Creating%20Words)
| 338 | 1985 B | Maximum Multiple Sum | [Question](https://codeforces.com/problemset/problem/1985/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20B%20-%20Maximum%20Multiple%20Sum)
| 339 | 1985 C | Good Prefixes | [Question](https://codeforces.com/problemset/problem/1985/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20C%20-%20Good%20Prefixes)
| 340 | 1985 D | Manhattan Circle | [Question](https://codeforces.com/problemset/problem/1985/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20D%20-%20Manhattan%20Circle)
| 341 | 1985 E | Secret Box | [Question](https://codeforces.com/problemset/problem/1985/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20E%20-%20Secret%20Box)
| 342 | 1985 F | Final Boss | [Question](https://codeforces.com/problemset/problem/1985/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20F%20-%20Final%20Boss)
| 343 | 1985 G | D-Function | [Question](https://codeforces.com/problemset/problem/1985/G) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20G%20-%20D-Function)
| 344 | 1986 A | X Axis | [Question](https://codeforces.com/problemset/problem/1986/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20A%20-%20X%20Axis)
| 345 | 1986 B | Matrix Stabilization | [Question](https://codeforces.com/problemset/problem/1986/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20B%20-%20Matrix%20Stabilization)
| 346 | 1986 C | Update Queries | [Question](https://codeforces.com/problemset/problem/1986/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20C%20-%20Update%20Queries)
| 347 | 1986 D | Mathematical Problem | [Question](https://codeforces.com/problemset/problem/1986/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20D%20-%20Mathematical%20Problem)
| 348 | 1986 E | Beautiful Array | [Question](https://codeforces.com/problemset/problem/1986/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1986%20E%20-%20Beautiful%20Array)