QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584486 | #6562. First Last | lucky_cloud | TL | 0ms | 3876kb | C++14 | 1.1kb | 2024-09-23 14:45:46 | 2024-09-23 14:45:46 |
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
3 attic climb alpha
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
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: 3844kb
input:
3 ccabaabbba acbbbacccb ccccccacba
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
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...