답안 #412270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412270 2021-05-26T16:26:08 Z amoo_safar Arranging Tickets (JOI17_arranging_tickets) C++17
65 / 100
1510 ms 19532 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

vector<int> G[N], H[N];
int n, m;

void Add_Edge(int u, int v){
	G[u].pb(v);
	H[v].pb(u);
}

int ps[N];

int Solve(int l, int r, int dif){
	memset(ps, 0, sizeof ps);
	multiset<int> ms;

	int res = 0;
	for(int i = l; i < r - 1; i++){
		for(auto x : G[i]){
			if(x >= r) continue;
			ps[i] ++;
			ps[x] --;
			ms.insert(x);
		}
		ps[i] += ps[i - 1];
		while(ps[i] > dif){
			int fr = *ms.rbegin();
			ms.erase(ms.find(fr));
			ps[i] -= 2;
			ps[fr] += 2;
			res ++;
		}
	}
	return res + dif;
}
int Calc(int i, int dif){
	if(i > n)
		i -= n;
	return Solve(i, i + n, dif);
}

int df[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	int a, b, c;
	for(int i = 0; i < m; i++){
		cin >> a >> b >> c;
		assert(c == 1);
		if(a > b) swap(a, b);
		df[a] ++;
		df[b] --;
		
		Add_Edge(a, b);
		Add_Edge(b, n + a);
		Add_Edge(n + a, n + b);
	}
	for(int i = 1; i <= n; i++) df[i] += df[i - 1];
	int id_mx = max_element(df + 1, df + n) - df;
	id_mx ++;
	int ans = min(Calc(id_mx, 0), Calc(id_mx, 1));
	for(int i = 1; i <= n; i++) ans = min(ans, Calc(i, 0));
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10444 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 7 ms 10444 KB Output is correct
4 Correct 8 ms 10444 KB Output is correct
5 Correct 7 ms 10444 KB Output is correct
6 Correct 7 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 8 ms 10444 KB Output is correct
9 Correct 7 ms 10488 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10500 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10444 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 7 ms 10444 KB Output is correct
4 Correct 8 ms 10444 KB Output is correct
5 Correct 7 ms 10444 KB Output is correct
6 Correct 7 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 8 ms 10444 KB Output is correct
9 Correct 7 ms 10488 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10500 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 32 ms 10444 KB Output is correct
17 Correct 26 ms 10532 KB Output is correct
18 Correct 27 ms 10528 KB Output is correct
19 Correct 25 ms 10532 KB Output is correct
20 Correct 27 ms 10532 KB Output is correct
21 Correct 26 ms 10444 KB Output is correct
22 Correct 26 ms 10436 KB Output is correct
23 Correct 26 ms 10536 KB Output is correct
24 Correct 26 ms 10444 KB Output is correct
25 Correct 26 ms 10444 KB Output is correct
26 Correct 25 ms 10444 KB Output is correct
27 Correct 26 ms 10572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10444 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 7 ms 10444 KB Output is correct
4 Correct 8 ms 10444 KB Output is correct
5 Correct 7 ms 10444 KB Output is correct
6 Correct 7 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 8 ms 10444 KB Output is correct
9 Correct 7 ms 10488 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10500 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 32 ms 10444 KB Output is correct
17 Correct 26 ms 10532 KB Output is correct
18 Correct 27 ms 10528 KB Output is correct
19 Correct 25 ms 10532 KB Output is correct
20 Correct 27 ms 10532 KB Output is correct
21 Correct 26 ms 10444 KB Output is correct
22 Correct 26 ms 10436 KB Output is correct
23 Correct 26 ms 10536 KB Output is correct
24 Correct 26 ms 10444 KB Output is correct
25 Correct 26 ms 10444 KB Output is correct
26 Correct 25 ms 10444 KB Output is correct
27 Correct 26 ms 10572 KB Output is correct
28 Correct 1497 ms 10876 KB Output is correct
29 Correct 1487 ms 10840 KB Output is correct
30 Correct 1455 ms 10848 KB Output is correct
31 Correct 1442 ms 10808 KB Output is correct
32 Correct 1441 ms 10808 KB Output is correct
33 Correct 1426 ms 10956 KB Output is correct
34 Correct 1476 ms 10828 KB Output is correct
35 Correct 1475 ms 10836 KB Output is correct
36 Correct 1510 ms 10840 KB Output is correct
37 Correct 1317 ms 10872 KB Output is correct
38 Correct 1307 ms 11012 KB Output is correct
39 Correct 1242 ms 10956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10444 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 7 ms 10444 KB Output is correct
4 Correct 8 ms 10444 KB Output is correct
5 Correct 7 ms 10444 KB Output is correct
6 Correct 7 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 8 ms 10444 KB Output is correct
9 Correct 7 ms 10488 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10500 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 32 ms 10444 KB Output is correct
17 Correct 26 ms 10532 KB Output is correct
18 Correct 27 ms 10528 KB Output is correct
19 Correct 25 ms 10532 KB Output is correct
20 Correct 27 ms 10532 KB Output is correct
21 Correct 26 ms 10444 KB Output is correct
22 Correct 26 ms 10436 KB Output is correct
23 Correct 26 ms 10536 KB Output is correct
24 Correct 26 ms 10444 KB Output is correct
25 Correct 26 ms 10444 KB Output is correct
26 Correct 25 ms 10444 KB Output is correct
27 Correct 26 ms 10572 KB Output is correct
28 Correct 1497 ms 10876 KB Output is correct
29 Correct 1487 ms 10840 KB Output is correct
30 Correct 1455 ms 10848 KB Output is correct
31 Correct 1442 ms 10808 KB Output is correct
32 Correct 1441 ms 10808 KB Output is correct
33 Correct 1426 ms 10956 KB Output is correct
34 Correct 1476 ms 10828 KB Output is correct
35 Correct 1475 ms 10836 KB Output is correct
36 Correct 1510 ms 10840 KB Output is correct
37 Correct 1317 ms 10872 KB Output is correct
38 Correct 1307 ms 11012 KB Output is correct
39 Correct 1242 ms 10956 KB Output is correct
40 Runtime error 15 ms 19532 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10444 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 7 ms 10444 KB Output is correct
4 Correct 8 ms 10444 KB Output is correct
5 Correct 7 ms 10444 KB Output is correct
6 Correct 7 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 8 ms 10444 KB Output is correct
9 Correct 7 ms 10488 KB Output is correct
10 Correct 7 ms 10444 KB Output is correct
11 Correct 7 ms 10444 KB Output is correct
12 Correct 7 ms 10444 KB Output is correct
13 Correct 7 ms 10500 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 32 ms 10444 KB Output is correct
17 Correct 26 ms 10532 KB Output is correct
18 Correct 27 ms 10528 KB Output is correct
19 Correct 25 ms 10532 KB Output is correct
20 Correct 27 ms 10532 KB Output is correct
21 Correct 26 ms 10444 KB Output is correct
22 Correct 26 ms 10436 KB Output is correct
23 Correct 26 ms 10536 KB Output is correct
24 Correct 26 ms 10444 KB Output is correct
25 Correct 26 ms 10444 KB Output is correct
26 Correct 25 ms 10444 KB Output is correct
27 Correct 26 ms 10572 KB Output is correct
28 Correct 1497 ms 10876 KB Output is correct
29 Correct 1487 ms 10840 KB Output is correct
30 Correct 1455 ms 10848 KB Output is correct
31 Correct 1442 ms 10808 KB Output is correct
32 Correct 1441 ms 10808 KB Output is correct
33 Correct 1426 ms 10956 KB Output is correct
34 Correct 1476 ms 10828 KB Output is correct
35 Correct 1475 ms 10836 KB Output is correct
36 Correct 1510 ms 10840 KB Output is correct
37 Correct 1317 ms 10872 KB Output is correct
38 Correct 1307 ms 11012 KB Output is correct
39 Correct 1242 ms 10956 KB Output is correct
40 Runtime error 15 ms 19532 KB Execution killed with signal 11
41 Halted 0 ms 0 KB -