QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620467#9251. Graph Changingucup-team5071WA 1ms3824kbC++143.1kb2024-10-07 18:19:532024-10-07 18:19:53

Judging History

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

  • [2024-10-07 18:19:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3824kb
  • [2024-10-07 18:19:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long
bool ava(int a,int b,int c){
    return abs(b-a) >= c;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--){
        int t,n,k,x,y;
        cin >> t >> n >> k >> x >> y;
        if (x > y) swap(x,y);
        if (t == 0){
            cout << y-x << "\n"; continue;
        } else if (k == 1){
            cout << 1 << "\n"; continue;
        } else if (t == 1){
            if (k >= n) {
                cout << -1 << "\n"; continue;
            } else if (y-x >= k){
                cout << 1 << "\n"; continue;
            } else {
                if (ava(x,n,k) && ava(y,n,k)){
                    cout << 2 << "\n"; continue;
                } else if (ava(x,1,k) && ava(y,1,k)){
                    cout << 2 << "\n"; continue;
                } else {
                    bool flag1 = (ava(x,1,k) || ava(x,n,k));
                    bool flag2 = (ava(y,1,k) || ava(y,n,k));
                    if (flag1 && flag2) {
                        cout << 3 << "\n"; continue;
                    } else {
                        cout << -1 << "\n"; continue;
                    }
                }
            }
        } else if (t >= 2){
            if (k == 2){
                if (n <= 3){
                    cout << -1 << "\n"; continue;
                } else {
                    if (t & 1){
                        cout << ((y-x==1)? 2 : 1)<< "\n"; continue;
                    } else {
                        cout << y-x << "\n"; continue;
                    }
                }
            } else if (k == 3 && t == 2){
                if (n == 6){
                    // assert(1==2);
                    vector<int> a{3,5,2,4};
                    int i1 = -1,j1 = -1;
                    for(int i = 0; i < 4; ++i) {if (a[i] == x)i1=i;if(a[i]==y)j1=i;}
                    if (i1 == -1 || j1 == -1){
                        cout << "-1\n"; continue;
                    } else {
                        cout << abs(i1-j1) << "\n"; continue;
                    }
                }
                if (ava(x,y,k)){
                    cout << -1 << "\n"; continue;
                } else if (ava(x,n,k) && ava(y,n,k)){
                    cout << -1 << "\n"; continue;
                } else if (ava(x,1,k) && ava(y,1,k)){
                    cout << -1 << "\n"; continue;
                } else {
                    bool flag1 = (ava(x,1,k) || ava(x,n,k));
                    bool flag2 = (ava(y,1,k) || ava(y,n,k));
                    if (flag1 && flag2) {
                        cout << 1 << "\n"; continue;
                    } else {
                        cout << -1 << "\n"; continue;
                    }
                }
            } else if (k == 3 && n == 6 && t == 3){
                // assert(1==2);
                cout << ((x==2&&y==5)? 1 : -1) << "\n"; continue;
            } else {
                cout << -1 << "\n"; continue;
            }
        }
    }   
    
    return 0;
}

详细

Test #1:

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

input:

5
1 5 3 2 4
1 10 4 2 4
2 10 5 2 4
1 3 2 1 3
1 3 2 1 2

output:

3
2
-1
1
-1

result:

ok 5 lines

Test #2:

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

input:

30
1 2 1 1 2
1 2 2 1 2
1 2 3 1 2
1 2 4 1 2
1 2 5 1 2
1 2 6 1 2
2 2 1 1 2
2 2 2 1 2
2 2 3 1 2
2 2 4 1 2
2 2 5 1 2
2 2 6 1 2
3 2 1 1 2
3 2 2 1 2
3 2 3 1 2
3 2 4 1 2
3 2 5 1 2
3 2 6 1 2
4 2 1 1 2
4 2 2 1 2
4 2 3 1 2
4 2 4 1 2
4 2 5 1 2
4 2 6 1 2
5 2 1 1 2
5 2 2 1 2
5 2 3 1 2
5 2 4 1 2
5 2 5 1 2
5 2 6 1 2

output:

1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1

result:

ok 30 lines

Test #3:

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

input:

90
1 3 1 1 2
1 3 1 1 3
1 3 1 2 3
1 3 2 1 2
1 3 2 1 3
1 3 2 2 3
1 3 3 1 2
1 3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-1
1
1
1
1
1
1
2
1
1
2
1
2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
1
1
1...

result:

wrong answer 82nd lines differ - expected: '3', found: '2'