답안 #105832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105832 2019-04-15T10:26:45 Z Pro_ktmr Solitaire (JOI16_solitaire) C++14
10 / 100
10 ms 896 KB
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)

#define MOD 1000000007

int N;
string S[3];
int st[3][2000];
LL wa[2000];
int c = 0;

LL dp[1<<16] = {};
LL solve(int now){
	if(now == (1<<c)-1) return 1;
	if(dp[now] != 0) return dp[now];
	LL re = 0;
	if(st[1][0] == 0 && (now>>0)%2 == 0) re += solve(now+(1<<0));
	for(int i=1; i<N-1; i++){
		if( st[0][i] != -1 && (now>>st[0][i])%2 == 0 && (st[0][i-1] == -1 || (now>>st[0][i-1])%2 == 1) && (st[0][i+1] == -1 || (now>>st[0][i+1])%2 == 1) )
			re += solve(now+(1<<st[0][i]));
		if( st[2][i] != -1 && (now>>st[2][i])%2 == 0 && (st[2][i-1] == -1 || (now>>st[2][i-1])%2 == 1) && (st[2][i+1] == -1 || (now>>st[2][i+1])%2 == 1) )
			re += solve(now+(1<<st[2][i]));
		if( st[1][i] != -1 && (now>>st[1][i])%2 == 0 && (st[1][i-1] == -1 || (now>>st[1][i-1])%2 == 1) && (st[1][i+1] == -1 || (now>>st[1][i+1])%2 == 1) )
			re += solve(now+(1<<st[1][i]));
		else if( st[1][i] != -1 && (now>>st[1][i])%2 == 0 && (st[0][i] == -1 || (now>>st[0][i])%2 == 1) && (st[2][i] == -1 || (now>>st[2][i])%2 == 1) )
			re += solve(now+(1<<st[1][i]));
	}
	if(st[1][N-1] == c-1 && (now>>(c-1))%2 == 0) re += solve(now+(1<<(c-1)));
	return dp[now] = re % MOD;
}

int main(){
	cin >> N >> S[0] >> S[1] >> S[2];
	if(S[0][0] == 'x' || S[0][N-1] == 'x' || S[2][0] == 'x' || S[2][N-1] == 'x'){
		cout << 0 << endl;
		return 0;
	}
	for(int i=0; i<N-1; i++){
		if(S[0][i] == 'x' && S[0][i+1] == 'x'){
			cout << 0 << endl;
			return 0;
		}
		if(S[2][i] == 'x' && S[2][i+1] == 'x'){
			cout << 0 << endl;
			return 0;
		}
	}
	for(int i=0; i<N; i++){
		if(S[0][i] == 'o') st[0][i] = -1;
		else{ st[0][i] = c; c++; }
		if(S[1][i] == 'o') st[1][i] = -1;
		else{ st[1][i] = c; c++; }
		if(S[2][i] == 'o') st[2][i] = -1;
		else{ st[2][i] = c; c++; }
	}
	if(c > 16) return -1;
	cout << solve(0) << endl;
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 10 ms 896 KB Output is correct
7 Correct 8 ms 880 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 9 ms 896 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 10 ms 896 KB Output is correct
7 Correct 8 ms 880 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 9 ms 896 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Runtime error 2 ms 384 KB Execution failed because the return code was nonzero
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 8 ms 640 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 9 ms 768 KB Output is correct
5 Correct 10 ms 896 KB Output is correct
6 Correct 10 ms 896 KB Output is correct
7 Correct 8 ms 880 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 9 ms 896 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Runtime error 2 ms 384 KB Execution failed because the return code was nonzero
14 Halted 0 ms 0 KB -