답안 #392540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392540 2021-04-21T10:06:19 Z patrikpavic2 결혼 문제 (IZhO14_marriage) C++17
96 / 100
1500 ms 3332 KB
#include <cstdio>
#include <cstring>
#include <vector>

#define PB push_back

using namespace std;

typedef long long ll;

const int N = (1 << 15);

int par[N], n, m, bio[N], k, un[N], cookie = 1;
vector < int > v[N];

bool dodaj(int x){
	if(bio[x] == cookie) return 0;
	bio[x] = cookie;
	for(int y : v[x]){
		if(un[y] && (par[y] == -1 || dodaj(par[y]))){
			par[x] = y; par[y] = x;
			return 1;
		}
	}
	return 0;
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 0;i < k;i++){
		int a, b; scanf("%d%d", &a, &b);
		a--; b--;
		v[a].PB(n + b), v[b + n].PB(a);
		//printf("VEZA %d %d\n", a, b + n);
	}
	memset(par, -1, sizeof(par));
	for(int i = 0;i < m;i++) un[i + n] = 1;
	int r = 0, sol = 0;
	ll ans = 0;
	for(int l = 0;l < n;l++){
		if(l){
			un[l - 1] = 0;
			if(par[l - 1] != -1){
				sol--; par[par[l - 1]] = -1;
				sol += dodaj(par[l - 1]); cookie++;
			}
		}		
		while(r < n && sol < m){
			un[r] = 1; sol += dodaj(r); cookie++;
			r++;
		}
		//printf("l = %d r = %d sol = %d\n", l, r, sol);
		ans += (n + 1 - r) * (sol == m);
	}
	printf("%lld\n", ans);
	return 0;
}


Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1188 KB Output is correct
8 Correct 1 ms 1184 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1188 KB Output is correct
13 Correct 1 ms 1188 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1100 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Correct 1 ms 1100 KB Output is correct
18 Correct 1 ms 1060 KB Output is correct
19 Correct 3 ms 1204 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1100 KB Output is correct
22 Correct 1 ms 1100 KB Output is correct
23 Correct 2 ms 1100 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 29 ms 1460 KB Output is correct
26 Correct 6 ms 1228 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 11 ms 1324 KB Output is correct
30 Correct 7 ms 1356 KB Output is correct
31 Correct 347 ms 1988 KB Output is correct
32 Correct 25 ms 1236 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 4 ms 1232 KB Output is correct
35 Correct 233 ms 2340 KB Output is correct
36 Correct 185 ms 2376 KB Output is correct
37 Correct 917 ms 2112 KB Output is correct
38 Correct 383 ms 2596 KB Output is correct
39 Correct 41 ms 1492 KB Output is correct
40 Correct 6 ms 1616 KB Output is correct
41 Correct 85 ms 1908 KB Output is correct
42 Correct 189 ms 1928 KB Output is correct
43 Correct 243 ms 2100 KB Output is correct
44 Correct 722 ms 2576 KB Output is correct
45 Correct 24 ms 2384 KB Output is correct
46 Execution timed out 1583 ms 3332 KB Time limit exceeded
47 Correct 1048 ms 3132 KB Output is correct
48 Correct 1028 ms 2984 KB Output is correct
49 Execution timed out 1590 ms 3196 KB Time limit exceeded
50 Correct 42 ms 1832 KB Output is correct