QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642898#7882. Linguistics Puzzleryh7WA 4ms9880kbC++172.5kb2024-10-15 16:57:232024-10-15 16:57:23

Judging History

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

  • [2024-10-15 16:57:23]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:9880kb
  • [2024-10-15 16:57:23]
  • 提交

answer

// Problem: I. Linguistics Puzzle
// Contest: Codeforces - The 2023 ICPC Asia Hefei Regional Contest (The 2nd Universal Cup. Stage 12: Hefei)
// URL: https://codeforces.com/gym/104857/problem/I
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using VI = vector<int>;
using PII = pair<int,int>;
using VVI = vector<vector<int>>;
const ll mod = 998244353;
const ll INF = 1e18;
const int N = 2e5 + 10;
string s[N];
int a[100][100];
int vis[100];
int tid(char c){
	if(c >= 'a' && c <= 'z'){
		return c - 'a';
	}else{
		return c - 'A';
	}
}
char toC(int p){
	if(p >= 0 && p < 26){
		return 'a' + p; 
	}else{
		return 'A' + p - 26;
	}
}
string res;
int n;
map<VI , VI> mp;
VVI z(52 , VI(3 , 0));
VVI y(52 , VI(3 , 0));
int dfs(int now){
	if(now == n) return 1;
	
	auto arr = y[now];
	for(auto c : mp[arr]){
		if(vis[c] == -1){
			res.push_back(toC(c));
			vis[c] = now;		
			if(dfs(now + 1)) return 1;
			vis[c] = -1;
			res.pop_back();
		}
	
	}
	return 0;

}

void solve(){
	res.clear();
	mp.clear();
	cin>>n;
	z.assign(n , VI(3 , 0));
	y.assign(n , VI(3 , 0));
	for(int i = 0 ; i < n * n ; i++){
		cin>>s[i];
		if(s[i].size() == 1){
			z[tid(s[i][0])][0]++;
		}else{
			z[tid(s[i][1])][0]++;
			z[tid(s[i][0])][1]++;
			if(s[i][0] == s[i][1]){
				z[tid(s[i][0])][2]++;
			}
			
		}
	}
	//cout<<tid('d');
	for(int i = 0 ; i < n ; i++){
		vis[i] = -1;
		mp[z[i]].push_back(i);
	}
	
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++){
			int w = i * j;
			y[w % n][0]++;
			if(w >= n) {
				y[w /n][1]++;
				if(w / n == w % n) y[w / n][2]++;
			}
			
				
		}
		//cout<<endl;
	}
	
	dfs(0);
	//cout<<dfs(0);
	/*vector<pair<int , char>> r;
	for(int i = 0 ; i < n ; i++){
		cout<<y[i][0]<<" ";
		cout<<y[i][1]<<" ";
		cout<<y[i][2]<<"\n";
	}
	cout<<endl;
	for(int i = 0 ; i < n ; i++){
		cout<<z[i][0]<<" ";
		cout<<z[i][1]<<" ";
		cout<<z[i][2]<<"\n";
	}*/
	cout<<res;
	
	cout<<endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for(int i = 0 ; i <= 52 ; i++){
    	for(int j = 0 ; j <= 52 ; j++){
    		a[i][j] = i * j;
    	
    	}
    }
    
    int T;cin>>T;while(T--)solve();
    
    
    
    // 0  0   0      0 
    // 0  1   2      3
    // 0  2   4(10)  6(12) 
    // 0  3   6(12)  9(22);
    
}


//5 4 3 2 1
//5 4 3 2 1

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

bca
dcba

result:

ok OK

Test #2:

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

input:

2
4
d a a bc ba bc b a a a d a a cb c c
4
a b da b b d ad b db b a c da b c b

output:

abcd
bdac

result:

ok OK

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 9840kb

input:

50
3
b b b a a c b b cc
4
d ab c ad d b ba ab c b d d d d d a
5
a aa aa ab ab ae b b e c c c ba c c c c dd d d dd c e c e
6
a ca a a a a a a ce a a b ba ba bc bc bd be e c c ca a cd cd be d d dc dc e e a eb f f
7
a a a a a a a a cf a a a a b b b b c c c cf a dd d dc d dd e f ed ee ee fb eg eg eg eg ...

output:

bca
dabc
cadbe
abcdef
aefdcgb
fcheabgd
bhgfedcia
jhcgfideba
fjbadkegcih
klhgjbaedcif
igkjmclfedhba
nflijahgmbdcek
anmlfijbgkhdceo
nofmlkjchdbegipa
aponblgjihcfqdkme
iqmonhckfrpgjedlba
prisodmbkjqghfencla
tcrdpoaklmjihfgeqsbn
utiraponmlksghjfecdbq
qotsrvjunmlkpiegfhdcba
pvutsrhwoimlkjnqgfedbca
xbvuts...

result:

wrong output format Unexpected end of file - token expected