QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#66128 | #5161. Last Guess | feeder1# | TL | 8ms | 3656kb | C++14 | 1.9kb | 2022-12-06 23:56:20 | 2022-12-06 23:56:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
set<ll> cmi[30], ez[30];
ll minx[30], cnt[30], curL[505];
vector<ll> aj[30];
bool maxn[30], vis[30];
bool aug(ll x) {
if ( vis[x] )return false;
vis[x] = true;
for ( auto it : aj[x] ) {
int a;
if ( curL[it] == -1 || aug(curL[it]) ) {
curL[it] = x;
return true;
}
}
return false;
}
int main() {
int n, m, i, j, k, b, c, a;
cin >> n >> m;
for ( i = 0; i < m; i++ )curL[i] = -1;
string str, str2;
for ( i = 0; i < n - 1; i++ ) {
cin >> str >> str2;
for ( j = 0; j < 26; j++ )cnt[j] = 0;
for ( j = 0; j < str.size(); j++ ) {
a = str[j] - 'a';
if ( str2[j] == 'G' ) {
curL[j] = a;
cnt[a]++;
ez[a].insert(j);
cmi[a].insert(j);
} else if ( str2[j] == 'Y' ) {
cnt[a]++;
cmi[a].insert(j);
} else {
cmi[a].insert(j);
maxn[a] = true;
}
}
for ( j = 0; j < 26; j++ )minx[j] = max(minx[j], cnt[j]);
}
for ( i = 0; i < 26; i++ ) {
for ( j = 0; j < 500; j++ ) {
if ( cmi[i].find(j) != cmi[i].end() )continue;
if ( curL[j] != -1 )continue;
aj[i].push_back(j);
}
}
for ( i = 0; i < 26; i++ ) {
for ( k = 0; k < minx[i] - ez[i].size(); k++ ) {
for ( j = 0; j < 26; j++ )vis[j] = false;
vis[i] = true;
for ( auto it : aj[i] ) {
if ( curL[it] == -1 || aug(curL[it]) ) {
curL[it] = i;
break;
}
}
}
}
ll cnt = 0;
for ( i = 0; i < m; i++ ) {
if ( curL[i] == -1 )cnt++;
}
for ( i = 0; i < 26 && cnt; i++ ) {
if ( maxn[i] )continue;
while ( cnt ) {
for ( j = 0; j < 26; j++ )vis[j] = false;
vis[i] = true;
bool done = false;
for ( auto it : aj[i] ) {
if ( curL[it] == -1 || aug(curL[it]) ) {
curL[it] = i;
done = true;
break;
}
}
if ( !done )break;
cnt--;
}
}
for ( i = 0; i < m; i++ ) {
char ch = curL[i] + 'a';
cout << ch;
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3396kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabacaaaddeb
result:
ok
Test #3:
score: 0
Accepted
time: 4ms
memory: 3552kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaa...
result:
ok
Test #4:
score: 0
Accepted
time: 8ms
memory: 3492k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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #6:
score: 0
Accepted
time: 4ms
memory: 3556kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #7:
score: -100
Time Limit Exceeded
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...