QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584481 | #6562. First Last | lucky_cloud | TL | 0ms | 3820kb | C++14 | 1.1kb | 2024-09-23 14:44:34 | 2024-09-23 14:44:35 |
Judging History
answer
#include <bits/stdc++.h>
#define vi vector<int>
using namespace std;
const int N = 1005;
int n, cnt[N][N], id[N], m;
string s;
map<vi, bool> mem;
bool dfs(vi a) {
if (mem.count(a)) return mem[a];
int p = a[9];
for (int i = 0; i < 3; ++i) if (a[p * 3 + i]) {
vi b = a;
b[p * 3 + i]--;
b[9] = i;
if (!dfs(b)) return mem[a] = 1;
}
return mem[a] = 0;
}
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s;
char S = s[0], T = s[s.size() - 1];
if (!id[S]) id[S] = ++m;
if (!id[T]) id[T] = ++m;
cnt[id[S]-1][id[T]-1]++;
}
int ans = 0;
for (int si = 0; si < 3; ++si)
for (int sj = 0; sj < 3; ++sj)
if (cnt[si][sj]) {
vi a(10);
for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) a[i * 3 + j] = cnt[i][j];
a[si * 3 + sj]--; a[9] = sj;
if (!dfs(a)) ans += cnt[si][sj];
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
3 attic climb alpha
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
22 agora alpha antic aorta apnea arena aroma attic basic blurb china circa civic climb cobra cocoa comic comma conic crumb cubic cynic
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 ccabaabbba acbbbacccb ccccccacba
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
11 mraa myga vtwm mala vvgm atvv vusm mznv avea atfv amgv
output:
7
result:
ok single line: '7'
Test #5:
score: -100
Time Limit Exceeded
input:
1000 vznwivhoprv pvzcjyruxv phykv vozinczup vbp vgjxfotuhzhobfp pbv vygphslv vpnqrfep vzrphpfggoqcgv vgdjmzuckyedpnp vatmaxfp ppnmmwtqmv paawwp pspoycv vcjthv ppcvagp pteiqdonkklp vav vcsxv priqwbalidav vinp phqeijnqkgbxv pwvmbivmgvouv vwzhndzmqpcwkmp pyzlv vtvblfov vrdv vzrfmjdnaruwp pfup pwzv vwyv...