답안 #38013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
38013 2017-12-30T09:11:39 Z alenam0161 결혼 문제 (IZhO14_marriage) C++14
20 / 100
43 ms 4140 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#include <cstdio>

#define ad push_back

using namespace std;
const int N = 30007;

int used[N];
vector<int> g[N];
int ma[N];
int qan = 0;
bool try_khun(int v){
	if (used[v])return false;
    used[v] = true;
	for (int to : g[v]){
		if (ma[to] == -1 || try_khun(ma[to])){
			//if (ma[to] == -1)qan++;
			ma[to] = v;
			return true;
		}
	}
	return false;
}
int main(){
	memset(ma, -1, sizeof(ma));
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= k; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].ad(v);
	}

	int l = 1;
	long long ans = 0;
	int cnt = 0;

	for (int i = 1; i <= n; i++)
	{
		while (cnt == m)
		{
			assert(l <= i);

			bool minus = false;
			
			for (auto x : g[l])
			{
				if (ma[x] == l)
				{
					ma[x] = -1;
					minus = true;
					break;
				}
			}

			cnt -= minus;
			l++;
		}

		cnt += try_khun(i);

		if (cnt == m)
		{
			ans += n - i + 1;
		}

	}

	cout << ans << endl;
	return 0;
}

Compilation message

marriage.cpp: In function 'int main()':
marriage.cpp:33:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &n, &m, &k);
                             ^
marriage.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2952 KB Output isn't correct
2 Incorrect 0 ms 2952 KB Output isn't correct
3 Incorrect 0 ms 2952 KB Output isn't correct
4 Incorrect 0 ms 2952 KB Output isn't correct
5 Correct 0 ms 2952 KB Output is correct
6 Correct 0 ms 2952 KB Output is correct
7 Incorrect 0 ms 2952 KB Output isn't correct
8 Correct 0 ms 2952 KB Output is correct
9 Correct 0 ms 2952 KB Output is correct
10 Correct 0 ms 2952 KB Output is correct
11 Incorrect 0 ms 2952 KB Output isn't correct
12 Correct 0 ms 2952 KB Output is correct
13 Incorrect 0 ms 2952 KB Output isn't correct
14 Incorrect 0 ms 2952 KB Output isn't correct
15 Incorrect 0 ms 2952 KB Output isn't correct
16 Incorrect 0 ms 2952 KB Output isn't correct
17 Incorrect 0 ms 2952 KB Output isn't correct
18 Incorrect 0 ms 2952 KB Output isn't correct
19 Incorrect 0 ms 2952 KB Output isn't correct
20 Incorrect 0 ms 2952 KB Output isn't correct
21 Correct 0 ms 2952 KB Output is correct
22 Incorrect 0 ms 2952 KB Output isn't correct
23 Incorrect 0 ms 2952 KB Output isn't correct
24 Incorrect 0 ms 2952 KB Output isn't correct
25 Incorrect 6 ms 3084 KB Output isn't correct
26 Incorrect 0 ms 2952 KB Output isn't correct
27 Correct 0 ms 2952 KB Output is correct
28 Incorrect 0 ms 2952 KB Output isn't correct
29 Incorrect 3 ms 3084 KB Output isn't correct
30 Incorrect 0 ms 3084 KB Output isn't correct
31 Incorrect 16 ms 3216 KB Output isn't correct
32 Incorrect 0 ms 3084 KB Output isn't correct
33 Correct 0 ms 2952 KB Output is correct
34 Incorrect 0 ms 2952 KB Output isn't correct
35 Incorrect 19 ms 3480 KB Output isn't correct
36 Incorrect 13 ms 3480 KB Output isn't correct
37 Incorrect 6 ms 3348 KB Output isn't correct
38 Incorrect 19 ms 3744 KB Output isn't correct
39 Incorrect 0 ms 3084 KB Output isn't correct
40 Correct 3 ms 3216 KB Output is correct
41 Incorrect 6 ms 3216 KB Output isn't correct
42 Incorrect 6 ms 3348 KB Output isn't correct
43 Incorrect 16 ms 3348 KB Output isn't correct
44 Incorrect 23 ms 3612 KB Output isn't correct
45 Incorrect 13 ms 3612 KB Output isn't correct
46 Incorrect 43 ms 4008 KB Output isn't correct
47 Incorrect 33 ms 3876 KB Output isn't correct
48 Incorrect 19 ms 3876 KB Output isn't correct
49 Incorrect 39 ms 4140 KB Output isn't correct
50 Incorrect 0 ms 3084 KB Output isn't correct