답안 #392544

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

#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;
int poc[N];
vector < int > v[N];

bool dodaj(int x){
	if(bio[x] == cookie) return 0;
	bio[x] = cookie;
	if(x >= n)
		while(poc[x] < (int)v[x].size() && !un[v[x][poc[x]]]) poc[x]++;
	for(int i = poc[x];i < (int)v[x].size() && un[v[x][i]];i++){
		if(par[v[x][i]] == -1 || dodaj(par[v[x][i]])){
			par[x] = v[x][i]; par[v[x][i]] = 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);
	}
	memset(par, -1, sizeof(par));
	for(int i = 0;i < m;i++){
		un[i + n] = 1;
		sort(v[i + n].begin(), v[i + n].end());
	}
	int r = 0, sol = 0;
	ll ans = 0;
	for(int l = 0;l < n;l++){
		if(l && sol == m){
			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++;
		}
		ans += (n + 1 - r) * (sol == m);
	}
	printf("%lld\n", ans);
	return 0;
}


Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
marriage.cpp:35:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 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 1100 KB Output is correct
8 Correct 1 ms 1100 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 1100 KB Output is correct
13 Correct 1 ms 1100 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 1100 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 1 ms 1100 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 2 ms 1100 KB Output is correct
25 Correct 13 ms 1356 KB Output is correct
26 Incorrect 5 ms 1240 KB Output isn't correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 8 ms 1228 KB Output is correct
30 Correct 7 ms 1228 KB Output is correct
31 Correct 115 ms 1796 KB Output is correct
32 Correct 19 ms 1228 KB Output is correct
33 Correct 1 ms 1228 KB Output is correct
34 Correct 4 ms 1228 KB Output is correct
35 Correct 243 ms 2372 KB Output is correct
36 Correct 198 ms 2172 KB Output is correct
37 Correct 340 ms 1988 KB Output is correct
38 Correct 389 ms 2584 KB Output is correct
39 Correct 42 ms 1448 KB Output is correct
40 Correct 5 ms 1484 KB Output is correct
41 Correct 82 ms 1652 KB Output is correct
42 Correct 225 ms 1884 KB Output is correct
43 Correct 278 ms 2012 KB Output is correct
44 Correct 798 ms 2500 KB Output is correct
45 Correct 17 ms 2260 KB Output is correct
46 Execution timed out 1599 ms 2908 KB Time limit exceeded
47 Correct 1189 ms 3060 KB Output is correct
48 Correct 1198 ms 3052 KB Output is correct
49 Execution timed out 1594 ms 3224 KB Time limit exceeded
50 Correct 44 ms 1624 KB Output is correct