답안 #17752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17752 2016-01-12T09:58:02 Z Erzhann 힘 센 거북 (IZhO11_turtle) C++
5 / 100
14 ms 9976 KB
/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's Adilkhan99 miaaaaaau      
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second 
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

                                            
const int MaxN = int (6e5) + 256;
const int INF = int(1e9);  
const int mod = (int)(1e9) + 7;
long long n, m, t, k, z;
long long f[MaxN];
pair<int, int> p[22];

int main () { _
	cin >> n >> m >> k >> t >> z;
	for(int i = 0; i < k; i++){
		int x, y; cin >> x >> y;
		p[i] = mp(x, y);
	}
	sort(p, p + k);
	f[0] = (1ll);
	for(int i = 1; i <= n + m; i++){
		f[i] = (f[i - 1] * (ll)(i));
	}
	long long ans = f[n + m] / f[n] / f[m];
	for(int i = 0; i < (1 << k); i++){
		ll cnt = (1ll);
		int last_i = 0, last_j = 0, kol = 0;
		bool ok = 1;
		for(int j = 0; j < k; j++){
			if((i & (1 << j))){
				if(last_j > p[j].second){
					ok = 0;
					break;
				}
				kol++;
				int I = p[j].first - last_i;
				int J = p[j].second - last_j;
				last_i = p[j].first;
				last_j = p[j].second;
				cnt = cnt * (f[I + J] / f[I] / f[J]);
			}
		}
		if(kol > t && ok){
			int I = n - last_i;
			int J = m - last_j;
			cnt = cnt * (f[I + J] / f[I] / f[J]);							                 	
			ans = ans - cnt;	
		}		
	}
	cout << ans % z;
return 0;
}                   									
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Runtime error 3 ms 504 KB Execution killed with signal 8 (could be triggered by violating memory limits)
5 Runtime error 3 ms 504 KB Execution killed with signal 8 (could be triggered by violating memory limits)
6 Runtime error 3 ms 504 KB Execution killed with signal 8 (could be triggered by violating memory limits)
7 Runtime error 3 ms 604 KB Execution killed with signal 8 (could be triggered by violating memory limits)
8 Runtime error 3 ms 504 KB Execution killed with signal 8 (could be triggered by violating memory limits)
9 Runtime error 3 ms 632 KB Execution killed with signal 8 (could be triggered by violating memory limits)
10 Runtime error 3 ms 760 KB Execution killed with signal 8 (could be triggered by violating memory limits)
11 Runtime error 7 ms 3708 KB Execution killed with signal 8 (could be triggered by violating memory limits)
12 Runtime error 13 ms 9976 KB Execution killed with signal 8 (could be triggered by violating memory limits)
13 Runtime error 12 ms 8440 KB Execution killed with signal 8 (could be triggered by violating memory limits)
14 Runtime error 7 ms 3576 KB Execution killed with signal 8 (could be triggered by violating memory limits)
15 Runtime error 6 ms 3576 KB Execution killed with signal 8 (could be triggered by violating memory limits)
16 Runtime error 14 ms 9592 KB Execution killed with signal 8 (could be triggered by violating memory limits)
17 Runtime error 12 ms 9208 KB Execution killed with signal 8 (could be triggered by violating memory limits)
18 Runtime error 13 ms 9976 KB Execution killed with signal 8 (could be triggered by violating memory limits)
19 Runtime error 13 ms 9976 KB Execution killed with signal 8 (could be triggered by violating memory limits)
20 Runtime error 14 ms 9976 KB Execution killed with signal 8 (could be triggered by violating memory limits)