QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#272441#7882. Linguistics Puzzleucup-team037#WA 16ms3708kbC++142.6kb2023-12-02 17:18:012023-12-02 17:18:02

Judging History

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

  • [2023-12-02 17:18:02]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:3708kb
  • [2023-12-02 17:18:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (long long) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define int long long
typedef pair<int,int> ii;

int n;
map<ii, vector<int> > M;
map<ii, vector<char> > Q;
vector< pair<vector<int>, vector<char> > > bruh;
vector<char> chars;
vector<string> stuff;
vector<string> stuff2;
char order[54];
bool found = false;

void recurse(int i){
	if(i == sz(bruh)){
		stuff2.clear();
		for(int i = 0;i < n;i++) for(int j = 0;j < n;j++){
			int x = i*j;
			
			string s = "";
			s += chars[x/n];
			s += chars[x%n];
			stuff2.push_back(s);
		}
		
		sort(all(stuff2));
		if(stuff == stuff2){
			found = true;
			return;
		}
		return;
	}
	vector<int> idx = bruh[i].first;
	vector<char> cs = bruh[i].second;
	
	vector<int> com = {};
	int m = sz(idx);
	for(int i = 0;i < m;i++) com.push_back(i);
	
	do{
		for(int i = 0;i < m;i++){
			order[idx[i]] = cs[i];
		}
		recurse(i+1);
	} while(next_permutation(all(com)));
}

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int TC; cin >> TC; while(TC--){
		int n; cin >> n;
		map<int,int> one;
		map<int,int> two;
		
		M.clear();
		Q.clear();
		bruh.clear();
		chars.clear();
		stuff.clear();
		stuff2.clear();

		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				int x = i*j;
				one[x%n]++;
				two[x/n]++;
			}
		}
		
		
		
		for(int i = 0;i < n;i++) M[ii(two[i], one[i])].push_back(i);
		
		
		char zero = 'a';
		map<string, int> common;
		
		stuff.clear();
		for(int i = 0;i < n*n;i++){
			string s; cin >> s;
			stuff.push_back(s);
			common[s]++;
		}
		
		for(auto p : common){
			if(p.second == 2*n - 1) zero = p.first[0];
		}
		
		set<char> charset;
		map<char, int> onec;
		map<char, int> twoc;
		for(string &s : stuff){
			if(sz(s) == 1) s = zero + s;
			onec[s[1]]++;
			twoc[s[0]]++;
			charset.insert(s[0]);
			charset.insert(s[1]);
		}
		
		chars.clear();
		for(char x : charset) chars.push_back(x);
		
		Q.clear();
		for(char x : charset) Q[ii(twoc[x], onec[x])].push_back(x);
		
		for(auto p : M){
			bruh.push_back({p.second, Q[p.first]});
		}
		
		found = false;
		sort(all(stuff));
		recurse(0);
		
		for(int i = 0;i < n;i++) cout << order[i];
		cout << '\n';
	}
	
	
}





Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3484kb

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: 3488kb

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: 16ms
memory: 3708kb

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
prisdombkjqghfencla
tcrdpoaklmjihfgeqsbn
utiraponmlksghjfecdbq
qotsrvjunmlkpiegfhdcba
pvutsrhwoimlkjnqgfedbca
xbvuts...

result:

wrong answer The product 2*12=24 is not in the output at case #17