Submission #2070025


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

string board[51];

int dx[] = { 0, 1, -1, 0 };
int dy[] = { 1, 0, 0, -1 };

class XorShift {
public:
    unsigned long x, y, z, w;
    XorShift() {
        x = 123456789; y = 362436069; z = 521288629; w = 88675123;
    }
    XorShift(unsigned long seed) {
        XorShift();
        w = seed;
        for (int i = 0; i < 100; ++i) (*this)();
    }
    unsigned long operator()() {
        unsigned long t = x ^ (x << 11);
        x = y; y = z; z = w;
        return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    }
};

static const unsigned long seed = 0UL;
XorShift rnd(seed);

vector<P> ans;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    rep(i, H) cin >> board[i];

    for (int i = 0; i < 8; ++i) {
        bool update = true;
        while (update) {
            update = false;
            rep(r, H) rep(c, W) {
                if (board[r][c] == '9'-i) {
                    P block[10];
                    priority_queue<pair<double, pair<int, int>>> que;
                    que.push( make_pair( 9, make_pair(r, c) ) );
                    int count = 0;
                    bitset<50*50+1> used;
                    used[r*50+c] = 1;
                    while (que.size() and count < 8) {
                        pair<int, P> tmp = que.top();
                        block[count++] = tmp.second;
                        que.pop();
                        int r = tmp.second.first, c = tmp.second.second;
                        rep(i, 4) {
                            int nr = r + dy[i], nc = c + dx[i];
                            if (nr < 0 or nr >= H or nc < 0 or nc >= W or used[nr*50+nc] == true or board[nr][nc] == 'x' or board[nr][nc] == '0') continue;
                            que.push(make_pair((board[nr][nc]-'0')+((double)rand()/RAND_MAX)*(((double)rand()/RAND_MAX)>0.5)*-1,make_pair(nr, nc)));
                            used[nr*50+nc] = 1;
                        }
                    }
                    if (count == 8) {
                        for (int i = 0; i < 8; ++i) {
                            int rr = block[i].first, cc = block[i].second;
                            board[rr][cc] = 'x';
                            ans.emplace_back(rr, cc);
                        }
                        update = true;
                    }
                }
            }
        }
    }

    cout << ans.size() / 8 << endl;
    rep(i, ans.size()/8*8) {
        cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
    }

    return 0;
}

Submission Info

Submission Time
Task A - Multiple Pieces
User dsytk7
Language C++14 (GCC 5.4.1)
Score 782042
Code Size 2932 Byte
Status AC
Exec Time 5 ms
Memory 256 KB

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 79049 / 1343058 72213 / 1343058 79528 / 1343058 68808 / 1343058 89189 / 1343058 76486 / 1343058 82527 / 1343058 71090 / 1343058 82302 / 1343058 80850 / 1343058
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 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 AC 5 ms 256 KB
subtask_01_02.txt AC 5 ms 256 KB
subtask_01_03.txt AC 5 ms 256 KB
subtask_01_04.txt AC 5 ms 256 KB
subtask_01_05.txt AC 5 ms 256 KB
subtask_01_06.txt AC 5 ms 256 KB
subtask_01_07.txt AC 5 ms 256 KB
subtask_01_08.txt AC 5 ms 256 KB
subtask_01_09.txt AC 5 ms 256 KB
subtask_01_10.txt AC 5 ms 256 KB