QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120044#2616. Attack OrdersolemnteeWA 2ms3624kbC++201.4kb2023-07-06 12:31:132023-07-06 12:31:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 12:31:13]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3624kb
  • [2023-07-06 12:31:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+5;
typedef long long ll;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        vector<int>a(n+1),b(n+1);
        ll sum=0;
        for(int i=1;i<=n;i++){
            scanf("%d%d",&a[i],&b[i]);
            sum+=b[i];
        }
        if(n==2){
            printf("Yes\n");
            continue;
        }
        vector<vector<int>>v(n+1,vector<int>()),v2(n+1,vector<int>());
        vector<int>in(n+1);
        bool flag=false;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++)if(j!=i){
                if(sum-b[i]+a[i]<=a[j]){
                    v[i].push_back(j);
                    v2[j].push_back(i);
                    in[i]++;
                }
            }
        }
        queue<int>q;
        vector<int>dp(n+1);
        for(int i=1;i<=n;i++)if(in[i]==0){
            q.push(i);
            dp[i]=1;
        }
        //printf("YES\n");
        while(!q.empty()){
            int p=q.front();
            q.pop();
            for(auto to:v2[p]){
                in[to]--;
                dp[to]=max(dp[to],dp[p]+1);
                if(in[to]==0){
                    q.push(to);
                }
            }
        }
        for(int i=1;i<=n;i++){
            if(dp[i]==n)flag=true;
        }
        if(flag)printf("Yes\n");
        else printf("No\n");

    }
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

3
2
15 25
10 5
3
7 0
7 3
10 0
3
10 10
20 20
30 30

output:

Yes
Yes
No

result:

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

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3620kb

input:

1000
4
0 1
0 2
2 2
0 0
4
2 2
1 1
1 1
0 0
4
2 1
1 2
1 0
2 1
3
2 1
1 0
1 1
4
2 0
2 2
1 2
1 2
3
1 0
3 0
0 3
4
1 1
1 0
1 2
1 2
2
1 2
3 1
4
1 2
1 0
2 0
0 2
2
3 3
0 2
4
2 0
1 0
2 1
0 1
3
1 1
1 0
0 3
4
1 1
2 1
0 2
1 1
4
1 2
2 2
1 0
2 1
4
0 0
1 0
0 1
0 1
3
0 1
2 3
0 0
3
3 1
3 2
1 1
4
1 0
0 0
1 1
2 1
4
2 1
1...

output:

No
No
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

wrong answer expected YES, found NO [134th token]