QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186845 | #5161. Last Guess | Forever_Young# | RE | 1ms | 3608kb | C++23 | 3.4kb | 2023-09-24 12:30:47 | 2023-09-24 12:30:47 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define per(i,n) for(int i=n;i>=1;--i)
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define N 500
#define M 510000
struct NetWorkFlow {
struct EDGE {
int adj, w, cost, next;
} edge[M*2];
int gh[N], q[N], dist[N], v[N], pre[N], prev[N], top;
int S, T;
void addedge(int x, int y, int w, int cost) {
edge[++top].adj = y;
edge[top].w = w;
edge[top].cost = cost;
edge[top].next = gh[x];
gh[x] = top;
edge[++top].adj = x;
edge[top].w = 0;
edge[top].cost = -cost;
edge[top].next = gh[y];
gh[y] = top;
}
void clear() {
top = 1;
memset(gh, 0, sizeof(gh));
}
int spfa() {
memset(dist, 63, sizeof(dist));
memset(v, 0, sizeof(v));
int head = 0, tail = 1;
q[1] = S; v[S] = 1; dist[S] = 0;
while (head != tail) {
(head += 1) %= N;
int x = q[head];
v[x] = 0;
for (int p=gh[x]; p; p=edge[p].next)
if (edge[p].w && dist[x] + edge[p].cost < dist[edge[p].adj]) {
dist[edge[p].adj] = dist[x] + edge[p].cost;
pre[edge[p].adj] = x;
prev[edge[p].adj] = p;
if (!v[edge[p].adj]) {
v[edge[p].adj] = 1;
(tail += 1) %= N;
q[tail] = edge[p].adj;
}
}
}
return dist[T] != inf;
}
int work() {
int ans = 0,flow=0;
while (spfa()) {
int mx = inf;
for (int x=T;x!=S;x=pre[x])
mx = min(edge[prev[x]].w, mx);
ans += dist[T] * mx;
flow+=mx;
for (int x=T;x!=S;x=pre[x]) {
edge[prev[x]].w -= mx;
edge[prev[x]^1].w += mx;
}
}
return flow;
}
} nwf;
char ans[510];
int l[30],r[30];
int can[510][30],id[30][510],fix[30];
int g,len;
char s[510],c[510];
int main()
{
cin>>g>>len;
for(int i=0;i<26;i++)l[i]=0,r[i]=len;
for(int i=1;i<=len;i++)
for(int j=0;j<26;j++)
can[i][j]=1;
rep(ii,g-1)
{
scanf("%s%s",s+1,c+1);
static int cur[30];
for(int i=0;i<26;i++)cur[i]=0;
rep(i,len)
if (c[i]=='G')
{
cur[s[i]-'a']++;
for(int j=0;j<26;j++)can[i][j]=0;
can[i][s[i]-'a']=1;
}
rep(i,len)
{
if (c[i]=='Y')
{
cur[s[i]-'a']++;
can[i][s[i]-'a']=0;
}
else
if (c[i]=='B')
{
r[s[i]-'a']=min(r[s[i]-'a'],cur[s[i]-'a']);
can[i][s[i]-'a']=0;
}
l[s[i]-'a']=max(l[s[i]-'a'],cur[s[i]-'a']);
}
}
nwf.S=0; nwf.T=len+26+1; nwf.clear();
rep(i,len)nwf.addedge(nwf.S,i,1,0);
rep(i,len)for(int j=0;j<26;j++)
if (can[i][j])
{
//cout<<i<<" "<<j<<endl;
id[i][j]=nwf.top+1;
nwf.addedge(i,len+j+1,1,0);
}
//cout<<l[4]<<" "<<r[4]<<endl;
for(int i=0;i<26;i++)
{
if (l[i]>r[i])continue;
nwf.addedge(len+i+1,nwf.T,l[i],-100000);
nwf.addedge(len+i+1,nwf.T,r[i]-l[i],0);
}
nwf.work();
rep(i,len)for(char c='a';c<='z';c++)
if (id[i][c-'a']!=0 && nwf.edge[id[i][c-'a']].w==0)putchar(c);
puts("");
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabacabbzdde
result:
ok
Test #3:
score: -100
Runtime Error
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...