QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#383943#8558. Grid Gamebulijiojiodibuliduo#WA 2ms3772kbC++171.5kb2024-04-09 19:07:162024-04-09 19:07:16

Judging History

你现在查看的是最新测评结果

  • [2024-04-09 19:07:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3772kb
  • [2024-04-09 19:07:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 rng(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

map<vector<PII>,bool> dp[2];
int n;
bool win(vector<PII> x,int a) {
	sort(all(x)); x.erase(unique(all(x)),x.end());
	if (!x.empty()&&x[0]==mp(0,0)) return false;
	if (dp[a].count(x)) return true;
	if (x.empty()) return dp[a][x]=true;
	//printf("? %d\n",SZ(x));
	if (a==0) {
		for (auto [p,q]:x) if (p==q) return dp[a][x]=false;
		vector<PII> y1,y2;
		for (auto p:x) {
			if (p.fi>0) y1.pb(mp(p.fi-1,p.se));
			if (p.se>0) y2.pb(mp(p.fi,p.se-1));
		}
		return win(y1,1)||win(y2,1);
	} else {
		for (auto &[p,q]:x) if (p<q) --q; else --p;
		return win(x,0);
	}
}
void solve() {
	scanf("%d",&n);
	dp[0].clear();
	dp[1].clear();
	vector<PII> p;
	rep(i,0,n) {
		int x,y;
		scanf("%d%d",&x,&y);
		p.pb(mp(x,y));
	}
	puts(win(p,0)?"Yes":"No");
}

int _;
int main() {
	for (scanf("%d",&_);_;_--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

3
1
3 3
2
2 0
1 2
4
2 0
2 3
1 6
5 2

output:

No
Yes
Yes

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3772kb

input:

1000
1
3 1
5
2 1
1 4
3 1
2 1
5 4
8
0 2
0 1
0 2
0 2
2 1
2 1
0 2
1 0
4
4 3
6 3
0 1
6 1
1
2 7
8
3 1
3 1
5 0
5 4
0 5
1 0
4 5
4 5
3
2 2
0 2
2 0
2
5 4
1 0
8
2 6
1 3
6 2
4 7
8 7
0 5
7 3
2 3
3
1 0
1 0
1 1
6
1 1
0 1
1 0
0 1
1 0
0 1
4
3 0
2 5
4 2
6 3
9
3 4
1 5
0 1
0 6
3 6
2 0
3 5
1 5
1 3
4
6 0
4 2
6 2
3 0
9
1...

output:

Yes
Yes
No
Yes
Yes
Yes
No
Yes
No
No
No
Yes
No
Yes
No
No
No
Yes
Yes
No
No
No
No
Yes
No
Yes
No
Yes
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No...

result:

wrong answer expected NO, found YES [6th token]