Submission #1140726


Source Code Expand

#include <cstdio>
#include <vector>

using namespace std;

int H, W, K;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int board[52][52];
bool used[52][52];

void solve() {
    int i, j, k, l;
    vector <pair<int, int> > ans;
    
    for (i = 1; i <= H; i++) {
        for (j = 1; j <= W; j++) {
            if (used[i][j] == true || board[i][j] == 0) continue;
            
            int best_score = 0, best_move;
            
            for (k = 0; k < (1 << ((K - 1) * 2)); k++) {
                int x = i, y = j, score = board[i][j];
                
                used[i][j] = true;
                
                for (l = 0; l < K - 1; l++) {
                    int move = (k >> (l * 2)) & 3;
                    
                    x += dx[move];
                    y += dy[move];
                    
                    if (used[x][y] == true || board[x][y] == 0) break;
                    
                    used[x][y] = true;
                    score *= board[x][y];
                }
                
                if (l == K - 1 && score > best_score) {
                    best_score = score;
                    best_move = k;
                }
                
                x = i, y = j;
                
                used[i][j] = false;
                
                for (l = 0; l < K - 1; l++) {
                    int move = (k >> (l * 2)) & 3;
                    
                    x += dx[move];
                    y += dy[move];
                    
                    if (used[x][y] == false || board[x][y] == 0) break;
                    
                    used[x][y] = false;
                }
            }
            
            if (best_score > 0) {
                int x = i, y = j;
                
                used[i][j] = true;
                ans.push_back(make_pair(i, j));
                
                for (l = 0; l < K - 1; l++) {
                    int move = (best_move >> (l * 2)) & 3;
                    
                    x += dx[move];
                    y += dy[move];
                    
                    used[x][y] = true;
                    ans.push_back(make_pair(x, y));
                }
            }
        }
    }
    
    printf("%d\n", ans.size() / K);
    for (i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second);
}

int main() {
    int i, j;
    
    scanf("%d %d %d", &H, &W, &K);
    
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            scanf("%1d", &board[i + 1][j + 1]);
        }
    }
    
    solve();
    
    return 0;
}

Submission Info

Submission Time
Task A - Multiple Pieces
User kawatea
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2697 Byte
Status WA
Exec Time 561 ms
Memory 892 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:79:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<std::pair<int, int> >::size_type {aka long unsigned int}’ [-Wformat=]
     printf("%d\n", ans.size() / K);
                                  ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:86:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &H, &W, &K);
                                  ^
./Main.cpp:90:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%1d", &board[i + 1][j + 1]);
                                               ^

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058
Status
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt WA 534 ms 892 KB
subtask_01_02.txt WA 528 ms 512 KB
subtask_01_03.txt WA 550 ms 512 KB
subtask_01_04.txt WA 556 ms 512 KB
subtask_01_05.txt WA 561 ms 512 KB
subtask_01_06.txt WA 533 ms 512 KB
subtask_01_07.txt WA 552 ms 512 KB
subtask_01_08.txt WA 552 ms 640 KB
subtask_01_09.txt WA 557 ms 512 KB
subtask_01_10.txt WA 534 ms 512 KB