Submission #600576

# Submission time Handle Problem Language Result Execution time Memory
600576 2022-07-21T05:29:59 Z 이동현(#8470) Arranging Tickets (JOI17_arranging_tickets) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    vector<vector<int>> a(m, vector<int>(3));
    for(int i = 0; i < m; ++i){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        --a[i][0], --a[i][1];
        int len = (a[i][1] + n - a[i][0]) % n;
        if(len * 2 > n){
            swap(a[i][0], a[i][1]);
        }
    }
    sort(a.begin(), a.end());
    int ans = (int)1e18;
    for(int i = 0; i < m; ++i){
        int j = i;
        while(true){
            vector<int> sum(n);
            for(int k = i; ; k = (k + 1) % m){
                if(a[k][0] < a[k][1]){
                    ++sum[a[k][0]];
                    --sum[a[k][1]];
                }
                else{
                    ++sum[a[k][0]];
                    ++sum[0];
                    --sum[a[k][1]];
                }
                if(k == j) break;
            }
            for(int k = (j + 1) % m; k != i; k = (k + 1) % m){
                swap(a[k][0], a[k][1]);
                if(a[k][0] < a[k][1]){
                    ++sum[a[k][0]];
                    --sum[a[k][1]];
                }
                else{
                    ++sum[a[k][0]];
                    ++sum[0];
                    --sum[a[k][1]];
                }
                swap(a[k][0], a[k][1]);
            }
            int mx = 0;
            for(int k = 0; k < n; ++k){
                if(k) sum[k] += sum[k - 1];
                mx = max(mx, sum[k]);
            }
            ans = min(ans, mx);
            j = (j + 1) % m;
            if(i == j) break;
        }
    }
    vector<int> sum(n);
    for(int k = 0; k != m; ++k){
        swap(a[k][0], a[k][1]);
        if(a[k][0] < a[k][1]){
            ++sum[a[k][0]];
            --sum[a[k][1]];
        }
        else{
            ++sum[a[k][0]];
            ++sum[0];
            --sum[a[k][1]];
        }
        swap(a[k][0], a[k][1]);
    }
    int mx = 0;
    for(int k = 0; k < n; ++k){
        if(k) sum[k] += sum[k - 1];
        mx = max(mx, sum[k]);
    }
    ans = min(ans, mx);
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 212 KB Output isn't correct
13 Halted 0 ms 0 KB -