답안 #766426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766426 2023-06-25T16:05:00 Z Znb_Jfrian Arranging Tickets (JOI17_arranging_tickets) C++14
0 / 100
1 ms 396 KB
//______________"In The Name Of GOD"______________

#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;


const int lg        = 20;
const int mod       = 1e9 + 7;
const ll  inf       = 1e9 + 100;
const int maxn      = 3e3 + 100;
    

#define cl       	clear
#define F        	first
#define S       	second
#define pb       	push_back
#define Sz(x)    	int((x).size())
#define all(x)   	(x).begin(), (x).end()

int a[maxn], b[maxn], ps[maxn], q, n;
vector <int> vc[maxn];
multiset <int> s;

inline int cal(int ind){
    fill(ps, ps + n, 0);
    for(int i = 0; i < q; i ++) a[i] = (a[i] - ind + n) % n, b[i] = (b[i] - ind + n) % n;
    for(int i = 0; i < q; i ++) {
        ps[min(a[i], b[i])] ++;
        ps[max(a[i], b[i])] --;
        vc[min(a[i], b[i])].pb(max(a[i], b[i]));
    }
    int ans = 0;
    for(int i = 0; i < n; i ++){
        while(!s.empty() && *s.begin() == i) s.erase(s.begin());
        if(i) ps[i] += ps[i - 1];
        for(auto x : vc[i]) s.insert(x);
        while(ps[i] > 0){
            int t = *s.rbegin();
            ps[i] -= 2, ps[t] += 2;
            s.erase(t);
            ans ++;
        }
    }
    for(int i = 0; i < q; i ++) a[i] = (a[i] + ind + n) % n, b[i] = (b[i] + ind + n) % n;
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    cin >> n >> q;
    for(int i = 0, c; i < q; i ++) cin >> a[i] >> b[i] >> c, a[i] --, b[i] --;
    int ans = inf;
    for(int i = 0; i < n; i ++) ans = min(ans, cal(i));
    cout << ans << '\n';
    return 0;
}

/*test case :

*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -