답안 #338783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338783 2020-12-23T22:23:16 Z Tosic 결혼 문제 (IZhO14_marriage) C++14
14 / 100
871 ms 1132 KB
#include <bits/stdc++.h>
#define maxn 100010
using namespace std;

long long ans;
int n,m, k, fMatch[maxn], iterNum[maxn], itV;

vector<vector<int> > gr;

bool dfs(int x, int& l, int& r){
	if(iterNum[x] == itV){
		return 0;
	}
	iterNum[x] = itV;
	for(auto i : gr[x]){
		if(i>=l and i <= r and (!fMatch[i] or dfs(fMatch[i], l, r)) ){
			fMatch[i] = x;
			return 1;
		}
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n >> m >> k;
	gr.resize(m+1, vector<int>());
	for(int i = 0; i < k; ++i){
		int a, b;
		cin >> a >> b;
		gr[b].push_back(a);
		//gr[b].push_back(a);
	}
	int j = 1;
	vector<int> notF;
	for(int i = 1; i <= m; ++i){
		notF.push_back(i);
	}
	for(int i = 1; i <= n; ++i){
		while(j <= n){

			if(!notF.size()){
				break;
			}
			for(int j0 = notF.size()-1; j0 >= 0; --j0){
				++itV;if(dfs(notF[j0], i, j)){
					notF.pop_back();
				} else {
					break;
				}
			}
			if(!notF.size()){
				break;
			}
			++j;
			//cerr << j << '\n';
		}
		if(notF.size()){
			break;
		}
		//cerr << j << '\n';
		ans += n-j;
		if(fMatch[i]){
			notF.push_back(fMatch[i]);
			fMatch[i] = 0;
		}
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Incorrect 1 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 0 ms 364 KB Output isn't correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 0 ms 364 KB Output isn't correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 0 ms 364 KB Output isn't correct
14 Incorrect 1 ms 364 KB Output isn't correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Incorrect 1 ms 364 KB Output isn't correct
17 Incorrect 1 ms 364 KB Output isn't correct
18 Incorrect 1 ms 364 KB Output isn't correct
19 Incorrect 2 ms 364 KB Output isn't correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Correct 1 ms 364 KB Output is correct
22 Incorrect 1 ms 364 KB Output isn't correct
23 Incorrect 1 ms 364 KB Output isn't correct
24 Incorrect 1 ms 364 KB Output isn't correct
25 Incorrect 38 ms 492 KB Output isn't correct
26 Incorrect 4 ms 364 KB Output isn't correct
27 Correct 1 ms 364 KB Output is correct
28 Incorrect 1 ms 364 KB Output isn't correct
29 Incorrect 2 ms 364 KB Output isn't correct
30 Incorrect 2 ms 364 KB Output isn't correct
31 Incorrect 343 ms 748 KB Output isn't correct
32 Incorrect 2 ms 384 KB Output isn't correct
33 Correct 1 ms 364 KB Output is correct
34 Incorrect 2 ms 364 KB Output isn't correct
35 Incorrect 178 ms 876 KB Output isn't correct
36 Incorrect 131 ms 1004 KB Output isn't correct
37 Incorrect 871 ms 952 KB Output isn't correct
38 Incorrect 19 ms 1004 KB Output isn't correct
39 Incorrect 77 ms 620 KB Output isn't correct
40 Correct 3 ms 492 KB Output is correct
41 Incorrect 5 ms 620 KB Output isn't correct
42 Incorrect 7 ms 620 KB Output isn't correct
43 Incorrect 10 ms 748 KB Output isn't correct
44 Incorrect 18 ms 1004 KB Output isn't correct
45 Incorrect 8 ms 748 KB Output isn't correct
46 Incorrect 30 ms 1132 KB Output isn't correct
47 Incorrect 28 ms 1004 KB Output isn't correct
48 Incorrect 20 ms 1004 KB Output isn't correct
49 Incorrect 27 ms 1132 KB Output isn't correct
50 Incorrect 220 ms 620 KB Output isn't correct