Submission #49750

# Submission time Handle Problem Language Result Execution time Memory
49750 2018-06-02T16:04:29 Z model_code None (JOI16_solitaire) C++11
100 / 100
241 ms 180716 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;
#define MOD 1000000007

Int dp[2006][6006][2];
Int c[4001][4001];
Int cnt[4001];
char board[3][2000];

vector<P> block;
void init(){
	for(Int i = 0;i < 4001;i++){
		for(Int j = 0;j <= i;j++){
			if(i == 0 || j == 0)c[i][j] = 1;
			else c[i][j] = c[i-1][j] + c[i-1][j-1];
			c[i][j] %= MOD;
		}
	}
}

void go(vector<Int> &vec){
	Int n = vec.size();
	if(n == 0)return;
	for(Int i = 0;i <= n;i++){
		for(Int j = 0;j <= 3 * (i+1);j++){
			dp[i][j][0] = dp[i][j][1] = 0;
		} 
	}

	vector<Int>sum = vec;
	for(Int i = 1;i < n;i++)sum[i] += sum[i-1];
	for(Int i = 0;i < n;i++){
		if(i == 0){
			if(vec[i] == 1){
				dp[0][1][1] = 1;
			}
			if(vec[i] == 2){                  
				dp[0][1][0] = 1;
				dp[0][2][1] = 1;
			}
			if(vec[i] == 3){                  
				dp[0][1][0] = 2;              
				dp[0][2][0] = 2;
				dp[0][3][1] = 2;
			}
			continue;
		}
		for(Int j = 1;j <= 3 * (i+1);j++){
			dp[i-1][j][1] += dp[i-1][j-1][1];
			dp[i-1][j][0] += dp[i-1][j-1][0];
		}
		if(vec[i] == 1){
			for(Int j = 1;j <= sum[i];j++){
				dp[i][j][1] += dp[i-1][sum[i-1]][1];
				dp[i][j][1] += dp[i-1][sum[i-1]][0] - dp[i-1][j-1][0];
				dp[i][j][1] %= MOD;
			}
		}
		
		
		if(vec[i] == 2){
			for(Int j = 1;j <= sum[i];j++){
//				dp[i][j][0] += dp[i-1][j-1][0] * (sum[i] - j);
				dp[i][j][0] += dp[i-1][j-1][1] * (sum[i] - j);
				dp[i][j][0] %= MOD;
				
				dp[i][j][1] += (dp[i-1][sum[i-1]][0] - dp[i-1][j-2][0]) * (j-1);
				dp[i][j][1] += dp[i-1][sum[i-1]][1] * (j-1);
				dp[i][j][1] %= MOD;
			}
		}
		
		
		if(vec[i] == 3){
			for(Int j = 1;j <= sum[i];j++){
//				dp[i][j][0] += dp[i-1][j-1][0] * (sum[i] - j) % MOD * (sum[i] - j - 1);
				dp[i][j][0] += dp[i-1][j-1][1] * (sum[i] - j) % MOD * (sum[i] - j - 1);
				dp[i][j][0] %= MOD;
				
				
//				if(j >= 2)dp[i][j][0] += dp[i-1][j-2][0] * (j-1) % MOD * (sum[i] - j) * 2;
				if(j >= 2)dp[i][j][0] += dp[i-1][j-2][1] * (j-1) % MOD * (sum[i] - j) * 2;
				dp[i][j][0] %= MOD;
				
				
				dp[i][j][1] += (dp[i-1][sum[i-1]][0] - dp[i-1][j-1][0]) * (j-1) % MOD * (j-2);
				dp[i][j][1] += dp[i-1][sum[i-1]][1] * (j-1) % MOD * (j-2);
				dp[i][j][1] %= MOD;
			}
		}
	}    
	
	Int res = 0;
	for(Int i = 1;i <= sum[n-1];i++){
		res += dp[n-1][i][0];
		res += dp[n-1][i][1];
		res %= MOD;
	}
	block.push_back(P(res, sum[n-1]));
}





int main(){
	init();
	Int black = 0;
	Int n;
	cin >> n;

	for(Int i = 0;i < 3;i++){
		for(Int j = 0;j < n;j++){
			cin >> board[i][j];
			if(board[i][j] == 'x')cnt[j]++, black++;
			if(board[i][j] != 'o' && board[i][j] != 'x' ){
//				cerr << "oxoxo" << endl;
//				exit(10);
			}
		}
	}
	if(board[0][0] == 'x' || board[2][0] == 'x' || board[0][n-1] == 'x' || board[2][n-1] == 'x'){
		cout << 0 << endl;
		return 0;
	}

	for(Int i = 0;i < n;i++){
		if(i == 0)continue;
		if(board[0][i-1] == 'x' && board[0][i] == 'x'){
			cout << 0 << endl;
			return 0;
		}
		if(board[2][i-1] == 'x' && board[2][i] == 'x'){
			cout << 0 << endl;
			return 0;
		}
	}	

	vector<Int> tmp;
	for(Int i = 0;i < n;i++){
		if(board[1][i] == 'o'){
			go(tmp);
			tmp.clear();
			if(board[0][i] == 'x')block.push_back(P(1, 1));
			if(board[2][i] == 'x')block.push_back(P(1, 1));
		}
		else{
			tmp.push_back(cnt[i]);
		}
	}
	go(tmp);
	
	Int res = 1;
	
	for(Int i = 0;i < block.size();i++){
		Int a = block[i].first;
		Int b = block[i].second;
		res *= a;res %= MOD;
		res *= c[black][b];res %= MOD;
		black -= b;
	}
	
	if(black != 0)cout << "PYA" << endl;
	res %= MOD;
	if(res < 0)res += MOD;
	cout << res << endl;
	return 0;
}

Compilation message

solitaire.cpp: In function 'int main()':
solitaire.cpp:162:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(Int i = 0;i < block.size();i++){
                ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 72 ms 78072 KB Output is correct
2 Correct 75 ms 78188 KB Output is correct
3 Correct 80 ms 78256 KB Output is correct
4 Correct 70 ms 78256 KB Output is correct
5 Correct 75 ms 78288 KB Output is correct
6 Correct 73 ms 78288 KB Output is correct
7 Correct 76 ms 78288 KB Output is correct
8 Correct 77 ms 78312 KB Output is correct
9 Correct 73 ms 78396 KB Output is correct
10 Correct 72 ms 78440 KB Output is correct
11 Correct 95 ms 78440 KB Output is correct
12 Correct 83 ms 78440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 78440 KB Output is correct
2 Correct 82 ms 78440 KB Output is correct
3 Correct 82 ms 78440 KB Output is correct
4 Correct 93 ms 78448 KB Output is correct
5 Correct 94 ms 78448 KB Output is correct
6 Correct 76 ms 78448 KB Output is correct
7 Correct 69 ms 78448 KB Output is correct
8 Correct 69 ms 78448 KB Output is correct
9 Correct 67 ms 78516 KB Output is correct
10 Correct 70 ms 78516 KB Output is correct
11 Correct 67 ms 78516 KB Output is correct
12 Correct 77 ms 78516 KB Output is correct
13 Correct 83 ms 82180 KB Output is correct
14 Correct 98 ms 84096 KB Output is correct
15 Correct 110 ms 91520 KB Output is correct
16 Correct 101 ms 91520 KB Output is correct
17 Correct 80 ms 91520 KB Output is correct
18 Correct 77 ms 91520 KB Output is correct
19 Correct 82 ms 91520 KB Output is correct
20 Correct 88 ms 91520 KB Output is correct
21 Correct 79 ms 91520 KB Output is correct
22 Correct 92 ms 92928 KB Output is correct
23 Correct 85 ms 92928 KB Output is correct
24 Correct 83 ms 92928 KB Output is correct
25 Correct 85 ms 92928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 92928 KB Output is correct
2 Correct 82 ms 92928 KB Output is correct
3 Correct 72 ms 92928 KB Output is correct
4 Correct 69 ms 92928 KB Output is correct
5 Correct 70 ms 92928 KB Output is correct
6 Correct 69 ms 92928 KB Output is correct
7 Correct 67 ms 92928 KB Output is correct
8 Correct 80 ms 92928 KB Output is correct
9 Correct 71 ms 92928 KB Output is correct
10 Correct 76 ms 92928 KB Output is correct
11 Correct 78 ms 92928 KB Output is correct
12 Correct 79 ms 92928 KB Output is correct
13 Correct 73 ms 92928 KB Output is correct
14 Correct 88 ms 92928 KB Output is correct
15 Correct 70 ms 92928 KB Output is correct
16 Correct 69 ms 92928 KB Output is correct
17 Correct 75 ms 92928 KB Output is correct
18 Correct 85 ms 92928 KB Output is correct
19 Correct 76 ms 92928 KB Output is correct
20 Correct 78 ms 92928 KB Output is correct
21 Correct 74 ms 92928 KB Output is correct
22 Correct 72 ms 92928 KB Output is correct
23 Correct 72 ms 92928 KB Output is correct
24 Correct 72 ms 92928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 78072 KB Output is correct
2 Correct 75 ms 78188 KB Output is correct
3 Correct 80 ms 78256 KB Output is correct
4 Correct 70 ms 78256 KB Output is correct
5 Correct 75 ms 78288 KB Output is correct
6 Correct 73 ms 78288 KB Output is correct
7 Correct 76 ms 78288 KB Output is correct
8 Correct 77 ms 78312 KB Output is correct
9 Correct 73 ms 78396 KB Output is correct
10 Correct 72 ms 78440 KB Output is correct
11 Correct 95 ms 78440 KB Output is correct
12 Correct 83 ms 78440 KB Output is correct
13 Correct 66 ms 92928 KB Output is correct
14 Correct 82 ms 92928 KB Output is correct
15 Correct 72 ms 92928 KB Output is correct
16 Correct 69 ms 92928 KB Output is correct
17 Correct 70 ms 92928 KB Output is correct
18 Correct 69 ms 92928 KB Output is correct
19 Correct 67 ms 92928 KB Output is correct
20 Correct 80 ms 92928 KB Output is correct
21 Correct 71 ms 92928 KB Output is correct
22 Correct 76 ms 92928 KB Output is correct
23 Correct 78 ms 92928 KB Output is correct
24 Correct 79 ms 92928 KB Output is correct
25 Correct 73 ms 92928 KB Output is correct
26 Correct 88 ms 92928 KB Output is correct
27 Correct 70 ms 92928 KB Output is correct
28 Correct 69 ms 92928 KB Output is correct
29 Correct 75 ms 92928 KB Output is correct
30 Correct 85 ms 92928 KB Output is correct
31 Correct 76 ms 92928 KB Output is correct
32 Correct 78 ms 92928 KB Output is correct
33 Correct 74 ms 92928 KB Output is correct
34 Correct 72 ms 92928 KB Output is correct
35 Correct 72 ms 92928 KB Output is correct
36 Correct 72 ms 92928 KB Output is correct
37 Correct 93 ms 92928 KB Output is correct
38 Correct 76 ms 92928 KB Output is correct
39 Correct 70 ms 92928 KB Output is correct
40 Correct 70 ms 92928 KB Output is correct
41 Correct 66 ms 92928 KB Output is correct
42 Correct 80 ms 92928 KB Output is correct
43 Correct 74 ms 92928 KB Output is correct
44 Correct 76 ms 92928 KB Output is correct
45 Correct 73 ms 92928 KB Output is correct
46 Correct 74 ms 92928 KB Output is correct
47 Correct 72 ms 92928 KB Output is correct
48 Correct 71 ms 92928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 78072 KB Output is correct
2 Correct 75 ms 78188 KB Output is correct
3 Correct 80 ms 78256 KB Output is correct
4 Correct 70 ms 78256 KB Output is correct
5 Correct 75 ms 78288 KB Output is correct
6 Correct 73 ms 78288 KB Output is correct
7 Correct 76 ms 78288 KB Output is correct
8 Correct 77 ms 78312 KB Output is correct
9 Correct 73 ms 78396 KB Output is correct
10 Correct 72 ms 78440 KB Output is correct
11 Correct 95 ms 78440 KB Output is correct
12 Correct 83 ms 78440 KB Output is correct
13 Correct 68 ms 78440 KB Output is correct
14 Correct 82 ms 78440 KB Output is correct
15 Correct 82 ms 78440 KB Output is correct
16 Correct 93 ms 78448 KB Output is correct
17 Correct 94 ms 78448 KB Output is correct
18 Correct 76 ms 78448 KB Output is correct
19 Correct 69 ms 78448 KB Output is correct
20 Correct 69 ms 78448 KB Output is correct
21 Correct 67 ms 78516 KB Output is correct
22 Correct 70 ms 78516 KB Output is correct
23 Correct 67 ms 78516 KB Output is correct
24 Correct 77 ms 78516 KB Output is correct
25 Correct 83 ms 82180 KB Output is correct
26 Correct 98 ms 84096 KB Output is correct
27 Correct 110 ms 91520 KB Output is correct
28 Correct 101 ms 91520 KB Output is correct
29 Correct 80 ms 91520 KB Output is correct
30 Correct 77 ms 91520 KB Output is correct
31 Correct 82 ms 91520 KB Output is correct
32 Correct 88 ms 91520 KB Output is correct
33 Correct 79 ms 91520 KB Output is correct
34 Correct 92 ms 92928 KB Output is correct
35 Correct 85 ms 92928 KB Output is correct
36 Correct 83 ms 92928 KB Output is correct
37 Correct 85 ms 92928 KB Output is correct
38 Correct 66 ms 92928 KB Output is correct
39 Correct 82 ms 92928 KB Output is correct
40 Correct 72 ms 92928 KB Output is correct
41 Correct 69 ms 92928 KB Output is correct
42 Correct 70 ms 92928 KB Output is correct
43 Correct 69 ms 92928 KB Output is correct
44 Correct 67 ms 92928 KB Output is correct
45 Correct 80 ms 92928 KB Output is correct
46 Correct 71 ms 92928 KB Output is correct
47 Correct 76 ms 92928 KB Output is correct
48 Correct 78 ms 92928 KB Output is correct
49 Correct 79 ms 92928 KB Output is correct
50 Correct 73 ms 92928 KB Output is correct
51 Correct 88 ms 92928 KB Output is correct
52 Correct 70 ms 92928 KB Output is correct
53 Correct 69 ms 92928 KB Output is correct
54 Correct 75 ms 92928 KB Output is correct
55 Correct 85 ms 92928 KB Output is correct
56 Correct 76 ms 92928 KB Output is correct
57 Correct 78 ms 92928 KB Output is correct
58 Correct 74 ms 92928 KB Output is correct
59 Correct 72 ms 92928 KB Output is correct
60 Correct 72 ms 92928 KB Output is correct
61 Correct 72 ms 92928 KB Output is correct
62 Correct 93 ms 92928 KB Output is correct
63 Correct 76 ms 92928 KB Output is correct
64 Correct 70 ms 92928 KB Output is correct
65 Correct 70 ms 92928 KB Output is correct
66 Correct 66 ms 92928 KB Output is correct
67 Correct 80 ms 92928 KB Output is correct
68 Correct 74 ms 92928 KB Output is correct
69 Correct 76 ms 92928 KB Output is correct
70 Correct 73 ms 92928 KB Output is correct
71 Correct 74 ms 92928 KB Output is correct
72 Correct 72 ms 92928 KB Output is correct
73 Correct 71 ms 92928 KB Output is correct
74 Correct 66 ms 92928 KB Output is correct
75 Correct 78 ms 92928 KB Output is correct
76 Correct 76 ms 92928 KB Output is correct
77 Correct 77 ms 92928 KB Output is correct
78 Correct 92 ms 92928 KB Output is correct
79 Correct 71 ms 92928 KB Output is correct
80 Correct 76 ms 92928 KB Output is correct
81 Correct 80 ms 92928 KB Output is correct
82 Correct 72 ms 92928 KB Output is correct
83 Correct 77 ms 92928 KB Output is correct
84 Correct 72 ms 92928 KB Output is correct
85 Correct 87 ms 92928 KB Output is correct
86 Correct 241 ms 180608 KB Output is correct
87 Correct 200 ms 180608 KB Output is correct
88 Correct 180 ms 180608 KB Output is correct
89 Correct 191 ms 180608 KB Output is correct
90 Correct 201 ms 180608 KB Output is correct
91 Correct 211 ms 180716 KB Output is correct
92 Correct 185 ms 180716 KB Output is correct
93 Correct 185 ms 180716 KB Output is correct
94 Correct 180 ms 180716 KB Output is correct
95 Correct 174 ms 180716 KB Output is correct
96 Correct 188 ms 180716 KB Output is correct
97 Correct 170 ms 180716 KB Output is correct