QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378712#8566. Can We Still Qualify For Semifinals?ucup-team3396#TL 1ms3848kbC++143.7kb2024-04-06 14:18:032024-04-06 14:18:05

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 14:18:05]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3848kb
  • [2024-04-06 14:18:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int head[20001];int to[20001];
int nxt[20001];int cur[20001];
long long flow[20001];
int dep[10001];
bool vis[10001];
int s,t;
int tot=2;
void add(int s,int t,int w){
	nxt[tot]=head[s];flow[tot]=w;
	to[tot]=t;head[s]=tot;tot++;
	return ;
}
void init(){
    for(int i=2;i<=tot;i++)head[i]=to[i]=nxt[i]=cur[i]=flow[i]=0;
    tot=2;
    return ;
}
bool bfs(){
	for(int i=1;i<=t;i++)dep[i]=vis[i]=0,cur[i]=head[i];
	queue<int> d;d.push(s);dep[s]=0;bool ok=0;vis[s]=1;
	while(!d.empty()){
		int g=d.front();d.pop();
		if(g==t)ok=1;
		for(int i=head[g];i;i=nxt[i]){
			if(flow[i]!=0 and !vis[to[i]])dep[to[i]]=dep[g]+1,vis[to[i]]=1,d.push(to[i]);
		}
	}
	return ok;
}
long long dfs(int g,long long pre){
	if(g==t)return pre;
	long long used=0;
	for(int i=cur[g];i;i=nxt[i]){
		cur[g]=i;
		if(dep[to[i]]==dep[g]+1 and flow[i]!=0){
		    long long res=dfs(to[i],min(flow[i],pre-used));
		    used+=res;
		    flow[i]-=res;
		    flow[i^1]+=res;
		}
		if(used==pre)return pre;
	}
	return used;
}
int solve(){
    int ans=0;
	while(bfs()){
		ans+=dfs(s,INT_MAX);
	}
	return ans;
}
int num[11];
pair<int,int> w[101];
int ttt=0;
int z;
bool vst[101];
signed main(){
    vector<int> o;
    //for(int i=1;i<=10;i++)o.push_back(i);
    for(int i=1;i<=9;i++){
        o.clear();
        o.push_back(1);
        for(int j=10-i+2;j<=10;j++)o.push_back(j);
        for(int j=2;j<=10-i+1;j++)o.push_back(j);
        for(int j=0;j<5;j++){
            ttt++;
            w[ttt]={o[j],o[9-j]};
        }
    }
    int T;cin>>T;
    while(T--){
        int len;cin>>len;
        string S;cin>>S;
        S=" "+S;
        for(int i=1;i<=10;i++)num[i]=0;
        z=S.size()-1;
        for(int i=1;i<S.size();i++){
            if(S[i]=='1')num[w[i].first]++;
            else num[w[i].second]++;
        }
        for(int i=z+1;i<=45;i++){
            if(w[i].first==1 or w[i].second==1)num[1]++;
        }
        bool ans=0;
        for(int i=2;i<=10;i++){
            for(int j=i+1;j<=10;j++){
                for(int k=j+1;k<=10;k++){
                    init();
                    bool flg=0;
                    for(int p=2;p<=10;p++){
                        if(p!=i and p!=j and p!=k and num[p]>num[1]){
                            flg=1;break;
                        }
                    }
                    if(flg)continue;
                    s=56,t=57;
                    int ooo=0;
                    for(int p=z+1;p<=45;p++){
                        if(w[p].first==1 or w[p].first==i or w[p].first==j or w[p].first==k or w[p].second==1 or w[p].second==i or w[p].second==j or w[p].second==k)continue;
                        ooo++;
                        add(s,p,1);add(p,s,0);
                    }
                    for(int p=2;p<=10;p++){
                        if(p==i or p==j or p==k)continue;
                        add(45+p,t,num[1]-num[p]);
                        add(t,45+p,0);
                    }
                    for(int p=z+1;p<=45;p++){
                        if(w[p].first==1 or w[p].first==i or w[p].first==j or w[p].first==k or w[p].second==1 or w[p].second==i or w[p].second==j or w[p].second==k)continue;
                        add(p,45+w[p].first,1);add(45+w[p].first,p,0);
                        add(p,45+w[p].second,1);add(45+w[p].second,p,0);
                    }
                    int qq=solve();
                    if(qq==ooo){
                        ans=1;break;
                    }
                }
                if(ans)break;
            }
            if(ans)break;
        }
        if(ans)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

input:

3
3
111
25
1000010101111111111010100
35
01111011110111101111011110111101111

output:

YES
YES
NO

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

10
16
0110000001010100
17
01111000110110101
15
001100010101111
16
0010101010011100
19
0000000100010110100
16
0011101010011100
18
011110010001100000
18
000110101001100011
20
01100010000100100100
15
001000111001101

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES

result:

ok 10 token(s): yes count is 10, no count is 0

Test #3:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

10
37
0110000001010100011101001011100110001
39
000100111101101001100101101000000000100
35
00111000100111100101011010111100100
33
010000010001110010110001101110001
30
000100010100000010010110101010
31
0000101000011010101001010000000
44
00001000000111101011010110000101100011000100
42
01111011110001001...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO

result:

ok 10 token(s): yes count is 0, no count is 10

Test #4:

score: -100
Time Limit Exceeded

input:

10
23
01100000010101000111010
38
01111001100011000101011110101001101001
27
010000000001001001110001001
26
01101001110011101101000110
8
00001000
22
0110100110001110110001
9
000100010
24
000000100101101010100100
6
011000
29
01101010100101000000000000100

output:

YES
NO
NO

result: