QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#198489#2832. Graph Theoryvanthoci#WA 10ms7540kbC++171.6kb2023-10-03 14:16:182023-10-03 14:16:18

Judging History

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

  • [2023-10-03 14:16:18]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:7540kb
  • [2023-10-03 14:16:18]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
#define fer(i,a,b) for(int i = a ; i <= b ; i ++)
using namespace std ;
using i64 = long long;
const int N = 1e6 + 10 ;

int n , m ;
int a[N] , b[N] ;
int c[N] ;

void get(int a , int b)
{
    if(a < b)
    {
        c[a] ++ , c[b] -- ;
    }
    else
    {
        //a -> n -> 1 -> b 
        c[a] ++ , c[n + 1] -- , c[1] ++ , c[b] -- ; 
    }
}

int get(int mid)
{
    fer(i,1,n) c[i] = 0 ;

    fer(i,1,n)
    {
        int l = a[i] , r = b[i] ;
        if(l > r) swap(l , r) ;
        
        int d1 = r - l ;
        int d2 = n - r + l ;

        //cout << l << " " << r << ' ' << d1 << " " << d2 << '\n' ;
        if(d1 <= mid && d2 <= mid)
        {
            get(1 , n + 1) ;
        }
        else if(d1 > mid && d2 > mid)
            return 0 ;
        else
        {
            if(d1 >= d2)
                get(l , r) ;
            else   
                get(r , l) ;
        }
    }

    fer(i,1,n)
    {
        c[i] += c[i - 1] ;
        //cout << c[i] << " \n"[i == n] ;
        if(c[i] >= n)
            return 1 ;
    }

    return 0 ;
}

void solve()
{
    fer(i,1,n)
        cin >> a[i] >> b[i] ;

    //get(1) ;
    // fer(i,0,n)
    //     cout << get(i) << '\n' ;

    int l = 0 , r = n ;
    while(l < r)
    {
        int mid = l + r >> 1 ;
        if(get(mid)) r = mid ;
        else l = mid + 1 ;
    }

    cout << l << '\n' ;
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    
    while(cin >> n >> m)
        solve() ;
    
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7492kb

input:

3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1

output:

1
0
2

result:

ok 3 lines

Test #2:

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

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 10ms
memory: 7540kb

input:

17 17
6 10
1 9
14 6
12 13
5 4
15 17
14 15
6 5
10 6
10 11
2 9
9 6
17 15
9 15
4 8
1 4
13 15
13 19
11 10
12 10
10 5
2 8
12 11
8 3
1 7
10 9
8 5
1 5
9 4
8 7
12 10
6 8
13 1
5 8
11 5
10 8
7 7
16 14
9 5
8 1
4 16
10 8
16 15
15 1
13 5
9 3
4 4
9 7
7 2
5 4
5 11
9 14
5 13
1 5
4 5
4 1
4 4
1 1
5 3
3 5
4 1
3 2
5 1
...

output:

8
6
3
3
5
2
1
0
1
3
1
1
0
2
1
1
0
5
5
3
4
6
0
2
2
4
3
9
5
10
4
3
3
2
5
1
5
3
2
2
9
7
3
3
6
4
1
6
5
2
6
6
4
5
5
4
2
2
1
2
5
1
4
2
1
2
1
1
3
1
2
9
2
3
2
7
2
7
5
5
1
1
1
0
1
0
2
0
1
0
0
0
1
4
6
1
7
8
4
2
2
2
1
3
9
4
8
1
2
3
2
6
6
1
2
2
2
2
0
1
1
0
0
0
1
0
0
1
0
2
2
1
8
4
5
4
3
4
4
7
11
3
2
1
2
2
4
3
2
...

result:

wrong answer 3rd lines differ - expected: '8', found: '3'