QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461010#8830. Breaking Badchenxinyang2006WA 0ms3944kbC++204.0kb2024-07-02 15:05:522024-07-02 15:05:52

Judging History

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

  • [2024-07-02 15:05:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3944kb
  • [2024-07-02 15:05:52]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int n,k;
int a[1005][1005],tag[2][1005],idx[2][15];
int b[1005],c[1005];//a[i][j]=b[i]+c[j]

int dp[1 << 6][5],ndp[1 << 6][5],_res[1 << 6][5],ans[5];
int main(){
//	freopen("test.in","r",stdin);
	scanf("%d",&n);
	rep(i,1,n){
		rep(j,1,n) scanf("%d",&a[i][j]);
	}

	int bas = 0;
	memset(tag,-1,sizeof(tag));
	while(1){
		int _idx = -1,px,py,fail = 1;
		per(i,n,1) if(tag[0][i] == -1) _idx = i;
		if(_idx == -1) break;

// 		printf("_idx=%d\n",_idx);
		rep(i,_idx + 1,n){
			if(tag[0][i] != -1) continue;
			px = py = -1;
			rep(j,1,n){
				if(tag[1][j] != -1) continue;
				if(px == -1){
					px = j;
				}else if((a[i][px] - a[_idx][px] + 5) % 5 != (a[i][j] - a[_idx][j] + 5) % 5){
					py = j;
					break;
				}
			}
			if(py != -1){
				idx[0][k] = _idx;idx[1][k] = px;
				tag[0][_idx] = tag[1][px] = k++;
				idx[0][k] = i;idx[1][k] = py;
				tag[0][i] = tag[1][py] = k++;
				fail = 0;
				break;
			}
		}
		if(fail){
			rep(j,1,n) if(tag[1][j] == -1) c[j] = a[_idx][j];
			rep(i,_idx + 1,n){
				if(tag[0][i] != -1) continue;
				rep(j,1,n) if(tag[1][j] == -1) b[i] = a[i][j] - c[j]; 
			}
			rep(i,1,n) bas += b[i] + c[i];
			bas %= 5;
			break;
		}
		if(k >= 4){
			printf("YYYYY\n");
			return 0;
		}
	}
/*	printf("k=%d\n",k);
	rep(i,1,n) printf("%d ",tag[0][i]);
	printf("\n");
	rep(i,1,n) printf("%d ",tag[1][i]);
	printf("\n");	
	rep(i,0,k - 1) printf("%d ",idx[0][i]);
	printf("\n");
	rep(i,0,k - 1) printf("%d ",idx[1][i]);
	printf("\n");	
	printf("bas=%d\n",bas);
	rep(i,1,n) printf("%d ",b[i]);
	printf("\n");
	rep(i,1,n) printf("%d ",c[i]);
	printf("\n");	*/

	dp[0][0] = 1;
	rep(i,1,n){	
		if(tag[0][i] != -1) continue;

		rep(j,0,k - 1){
			rep(S,0,(1 << k) - 1){
				if((S >> j) & 1) continue;
				rep(v,0,4) ndp[S + (1 << j)][(v + a[i][idx[1][j]] + 5 - b[i]) % 5] |= dp[S][v];
			}
		}
		rep(S,0,(1 << k) - 1){
			rep(v,0,4){
				dp[S][v] |= ndp[S][v];
				ndp[S][v] = 0;
			}
		}
	}
	rep(S,0,(1 << k) - 1) copy(dp[S],dp[S] + 5,_res[S]);
/*	rep(S,0,(1 << k) - 1){
		rep(v,0,4) printf("%d",_res[S][v]);
		printf("\n");
	}*/

	rep(SS,0,(1 << k) - 1){//已经选了 S 集合的关键行
		memset(dp,0,sizeof(dp));
		rep(v,0,4) dp[0][v] = _res[SS][v];
//		rep(v,0,4) printf("%d",dp[0][v]);
//		printf("\n");
		rep(i,1,n){
			if(tag[1][i] == -1){	
				rep(j,0,k - 1){
					rep(S,0,(1 << k) - 1){
						if((S >> j) & 1) continue;
						rep(v,0,4) ndp[S + (1 << j)][(v + a[idx[0][j]][i]) % 5] |= dp[S][v];
					}
				}
				rep(S,0,(1 << k) - 1){
					rep(v,0,4){
						dp[S][v] |= ndp[S][v];
						ndp[S][v] = 0;
					}
				}
				continue;
			}
			if((SS >> tag[1][i]) & 1) continue;
			rep(j,0,k - 1){
				rep(S,0,(1 << k) - 1){
					if((S >> j) & 1) continue;
					rep(v,0,4) ndp[S + (1 << j)][(v + a[idx[0][j]][i] + 5 - c[i]) % 5] |= dp[S][v];
				}
			}
			rep(S,0,(1 << k) - 1){
				rep(v,0,4){
					dp[S][v] = ndp[S][v];
					ndp[S][v] = 0;
				}
			}
		}
		rep(v,0,4) ans[(v + bas) % 5] |= dp[(1 << k) - 1][v];
	}
	rep(v,0,4){
		if(ans[v]) printf("Y");
		else printf("N");
	}
	return 0;
}

詳細信息

Test #1:

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

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3912kb

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

YYYYY

result:

wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYYY'