QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#79892#2931. Tri-Color Puzzleantc3WA 2ms3816kbC++142.5kb2023-02-21 07:38:222023-02-21 07:38:25

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-21 07:38:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3816kb
  • [2023-02-21 07:38:22]
  • 提交

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][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, upright =3;
    if(r > 0){
        if(c > 0){
            upleft = color[r-1][c-1];
        }
        if(c < r-1){
            upright = color[r-1][c];
        }
    }
    if(c > 0){
        left = color[r][c-1];
    }
    if(r == 4){
        if(DEBUG) printColor();
    }
    //upleft -1
    if(DEBUG) cout << "upleft: " << upleft << " left: " << left <<" upright: " << upright <<  " col: " << col<<endl; 
    if(DEBUG) cout << "cur dp: " << dp[r][c][col][upleft][left][upright]<< endl;
    if(dp[r][c][col][upleft][left][upright] != -1){
        return dp[r][c][col][upleft][left][upright];
    }
    if(color[r][c] != col && color[r][c] != -1){
        dp[r][c][col][upleft][left][upright] = 0;
        return 0;
    }
    //cases upleft left and col are equal
    if(DEBUG)cout << "cheking upper left triangle\n";
    if(!((upleft == 3) || (left == 3) || (upleft == left && left == col) || (upleft != left && left != col && col != upleft))){
        dp[r][c][col][upleft][left][upright] = 0;
        return 0;
    }
    if(DEBUG) cout << "passed initial checks!" << endl;
    dp[r][c][col][upleft][left][upright] = 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][upright] = 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][0], &dp[0][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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

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: 0ms
memory: 3812kb

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: 2ms
memory: 3808kb

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: 0
Accepted
time: 2ms
memory: 3644kb

input:

6 4
1 1 0
2 2 0
5 1 1
5 5 2

output:

9

result:

ok single line: '9'

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3812kb

input:

17 16
3 2 2
4 4 0
5 2 1
6 4 1
8 5 2
8 8 2
11 1 2
11 7 0
12 4 2
12 10 2
12 11 0
13 11 2
14 5 2
14 8 0
16 7 0
17 5 1

output:

0

result:

wrong answer 1st lines differ - expected: '3', found: '0'