QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591338#7882. Linguistics PuzzlelimpidCompile Error//C++143.3kb2024-09-26 15:28:312024-09-26 15:28:31

Judging History

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

  • [2024-09-26 15:28:31]
  • 评测
  • [2024-09-26 15:28:31]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
inline int read(){
    int f=1,ans=0; char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN = 65;
int cas, A[MAXN][MAXN];
int Q(char c){
	if(c >= 'a' && c <= 'z') return c - 'a';
	return 26 + c - 'A';
}
char Q_(int x){
	if(x <= 25) return 'a' + x;
	return (x - 26) + 'A';
}
int buc[MAXN][MAXN]; bool vis[MAXN]; int Ans[MAXN], N, GGG[MAXN];
vector<int> vec[MAXN], g, vec1[MAXN];
char str[5];
char Ans_i[MAXN];
void Print(vector<int> t){
	for(auto w: t) printf("%d ", w); printf("\n");
	return;
}
int buc1[MAXN * MAXN];
bool check(){
	memset(buc1, 0, sizeof(buc1));
	for(int i = 0; i < N; i++) buc1[Ans[i]] += GGG[i];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(buc[i][j]){
				if(Ans[i] == 0) assert(0); 
				buc1[Ans[i] * N + Ans[j]] += buc[i][j];
			}
		}
	}
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++){
		if(buc1[i * j] == 0) return 0;
		buc1[i * j]--;
	}return 1;
}
int main(){
	//freopen("1.in", "r", stdin);
	cas = read();
	while(cas--){
		N = read(); for(int i = 0; i < N; i++) vec[i].clear(), vec1[i].clear();
		memset(A, 0, sizeof(A)); memset(buc, 0, sizeof(buc)); memset(GGG, 0, sizeof(GGG));
		memset(vis, 0, sizeof(vis));
		memset(Ans, -1, sizeof(Ans));
		for(int i = 1; i <= N * N; i++){
			scanf("%s", str + 1); int len = strlen(str + 1);
			if(len == 1) GGG[Q(str[1])]++;
			else buc[Q(str[1])][Q(str[2])]++;
		}
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				int w = i * j;
				A[w / N][w % N]++;
			}
		}
		vec[0].pb(2 * N - 1);
		for(int i = 1; i < N; i++){
			g.clear();
			for(int j = 0; j < N; j++) if(A[i][j]) g.pb(A[i][j]);
			sort(g.begin(), g.end());
			vec[i] = g;
			vec[i].pb(A[0][i]);
		}
		for(int i = 0; i < N; i++){
			g.clear();
			for(int j = 0; j < N; j++) if(buc[i][j]){
				g.pb(buc[i][j]);
			}
			sort(g.begin(), g.end());
			vec1[i] = g; vec1[i].pb(GGG[i]);
		}
		for(int i = 0; i < N; i++){
			if(GGG[i] == 2 * N - 1){
				Ans[i] = 0; vis[0] = 1; continue;
			}
			for(int j = 1; j < N; j++){
				if(vis[j]) continue;
				if(vec1[i].size() != vec[j].size()) continue;
				bool flag = 1;
				for(int k = 0; k < vec1[i].size(); k++) flag &= (vec1[i][k] == vec[j][k]);
				if(flag){
					Ans[i] = j; vis[j] = 1; break;
				}
			}
		}
		int px = -1, py = -1;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(i == j) continue;
				if(vec[i].size() != vec[j].size()) continue; bool flag = 1;
				for(int t = 0; t < vec[i].size(); t++) flag &= (vec[i][t] == vec[j][t]);
				if(flag){
					px = i, py = j;
					break;
				}
			}
		}
		int posx = -1, posy = -1;
		if(px != -1){
			for(int i = 0; i < N; i++) if(Ans[i] == px){posx = i; break;}
			for(int i = 0; i < N; i++) if(Ans[i] == py){posy = i; break;}
		}
		if(!check()){
			swap(Ans[posx], Ans[posy]);
		}
		for(int i = 0; i < N; i++) Ans_i[Ans[i]] = Q_(i);
		for(int i = 0; i < N; i++) cout << Ans_i[i]; cout << endl;

	}
}/*
2
3
a b a b b b b c cc
4
d d d d d c b a d b cd cb d a cb bc
*/

Details

answer.code: In function ‘bool check()’:
answer.code:42:49: error: ‘assert’ was not declared in this scope
   42 |                                 if(Ans[i] == 0) assert(0);
      |                                                 ^~~~~~
answer.code:6:1: note: ‘assert’ is defined in header ‘<cassert>’; did you forget to ‘#include <cassert>’?
    5 | #include<vector>
  +++ |+#include <cassert>
    6 | #define fi first
answer.code: In function ‘int main()’:
answer.code:61:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |                         scanf("%s", str + 1); int len = strlen(str + 1);
      |                         ~~~~~^~~~~~~~~~~~~~~