QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642934 | #7882. Linguistics Puzzle | ryh7 | WA | 8ms | 9976kb | C++17 | 2.9kb | 2024-10-15 17:10:17 | 2024-10-15 17:10:18 |
Judging History
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];
vector<string> ts;
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));
map<int,char> f;
int dfs(int now){
if(now == n){
vector<string> tmp;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
int p0 = a[i][j] % n;
int p1 = a[i][j] / n;
//cout<<res[p0];
string k;
if(p1 == 0){
k += (res[p0]);
}else{
k += (res[p1]);
k += (res[p0]);
}
tmp.push_back(k);
}
}
sort(tmp.begin() , tmp.end());
bool flag = 1;
for(int i = 0 ; i < n * n ; i++){
//cout<<tmp[i]<<" ";
if(ts[i] != tmp[i]) flag = 0;
}
//cout<<endl;
return flag;
}
auto arr = y[now];
for(auto c : mp[arr]){
if(vis[c] == -1){
//if(now == 1) cout<<c<<" ";
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();
ts.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]++;
}
}
ts.push_back(s[i]);
}
sort(ts.begin() , ts.end());
//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<<vis[0]<<" ";
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
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9852kb
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: 9916kb
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: 8ms
memory: 9976kb
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