1 Like
Thanku very much
1 Like
Getting wrong answer for the following. Please help me with this.
from collections import defaultdict
def solve():
for _ in range(int(input())):
n = int(input())
freq_1 = defaultdict(lambda: 0)
freq_2 = defaultdict(lambda: 0)
for __ in range(n):
x, y = map(int, input().split())
if x + y <= n + 1:
freq_1[x + y] += 1
else:
freq_2[n - x + n - y + 1] += 1
for key in freq_1.keys():
if key - 1 == freq_1[key]:
print('NO')
return
for key in freq_2.keys():
if key == freq_2[key]:
print('NO')
return
print('YES')
solve()
Consider the test input:
2
2
1 2
2 1
2
1 2
2 1
Why my code gives a WA?
#include<bits/stdc++.h>
#define Endl ‘\n’
#define pb push_back
#define ll long long int
#define fi(x,n) for(ll i=x;i<n;i++)
using namespace std;
void solve()
{
ll n;
cin>>n;
vector < pair<ll,ll> > vp;
map < pair<ll,ll> ,ll > m;
fi(0,n)
{
ll x,y;
cin>>x>>y;
m[{x,y}]=1;
vp.pb({x,y});
}
ll res=0;
map < pair<ll,ll>,ll > vis;
fi(0,n)
{
ll x=vp[i].first,y=vp[i].second;
if(!vis[{x,y}])
{
ll len=1,tempx=x-1,tempy=y+1;
while(m[{tempx,tempy}])
{
vis[{tempx,tempy}]=1;
len++;
tempx--;tempy++;
}
tempx=x+1;tempy=y-1;
while(m[{tempx,tempy}])
{
vis[{tempx,tempy}]=1;
len++;
tempx++;tempy--;
}
if(len==1+min(x-1,n-y)+min(n-x,y-1))
res=1;
}
}
if(res)
cout<<"NO";
else
cout<<"YES";
cout<<Endl;
}
int main()
{
ll t;
scanf("%lld",&t);
while(t–)
solve();
return 0;
}
Nice approach!
What category would you put this question in?
was it adhoc or just observation
I’d say it was just an observation based problem.
1 Like