QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#79891 | #2931. Tri-Color Puzzle | antc3 | WA | 2ms | 3560kb | C++14 | 2.2kb | 2023-02-21 07:24:15 | 2023-02-21 07:24:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define MAXS 20
int S, I;
int color[MAXS][MAXS];
int dp[MAXS][MAXS][3][4][4];
const bool DEBUG = false;
void printColor(){
for(int i = 0; i < S; i++){
for(int j = 0; j <= i; j++){
cout << color[i][j] << " ";
}
cout << endl;
}
}
int dfs(int r, int c, int col){
if(DEBUG) cout << r << " " << c << " "<< col << endl;
if(r >= S) return 0;
if(c > r) return 0;
int upleft =3, left = 3;
if(r > 0){
if(c > 0){
upleft = color[r-1][c-1];
}
}
if(c > 0){
left = color[r][c-1];
}
if(r == 3){
if(DEBUG) printColor();
}
//upleft -1
if(dp[r][c][col][upleft][left] != -1){
return dp[r][c][col][upleft][left];
}
if(color[r][c] != col && color[r][c] != -1){
dp[r][c][col][upleft][left] = 0;
return 0;
}
//cases upleft left and col are equal
if(DEBUG)cout << "cheking upper left triangle\n";
if(DEBUG) cout << "upleft: " << upleft << " left: " << left << " col: " << col<<endl;
if(!((upleft == 3) || (left == 3) || (upleft == left && left == col) || (upleft != left && left != col && col != upleft))){
dp[r][c][col][upleft][left] = 0;
return 0;
}
if(DEBUG) cout << "passed initial checks!" << endl;
dp[r][c][col][upleft][left] = 1;
if(c == S-1) return 1;
bool changed = false;
if(color[r][c] == -1){
color[r][c] = col;
changed = true;
}
int sum = 0;
if(c == r){
for(int i= 0; i < 3; i++){
sum+=dfs(r+1,0,i);
}
}
else{
for(int i = 0; i < 3; i++){
sum+=dfs(r,c+1,i);
}
}
if(changed) color[r][c] = -1;
return dp[r][c][col][upleft][left] = sum;
}
int main(){
cin >> S >> I;
fill(&color[0][0], &color[0][0] + sizeof(color)/4,-1);
for(int i =0; i< I; i++){
int a,b,c;
cin >> a >> b >> c;
a--; b--;
color[a][b] = c;
}
fill(&dp[0][0][0][0][0], &dp[0][0][0][0][0]+sizeof(dp)/4,-1);
int ans = 0;
for(int i = 0 ; i < 3; i++){
ans+=dfs(0,0,i);
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3316kb
input:
4 4 1 1 0 2 1 2 4 1 2 4 4 2
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
4 4 1 1 1 2 1 2 4 1 2 3 3 2
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
4 4 1 1 0 2 1 1 4 1 0 4 4 0
output:
3
result:
ok single line: '3'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 3408kb
input:
6 4 1 1 0 2 2 0 5 1 1 5 5 2
output:
0
result:
wrong answer 1st lines differ - expected: '9', found: '0'