Contest Duration: ~ (local time) (480 minutes)

Submission #11353684

Source Code Expand

Copy
```/**
* code generated by JHelper
* @author TM
*/

#include <bits/stdc++.h>

#define MOD 1e9+7

using namespace std;

class a {
public:
static void solve(std::istream &cin, std::ostream &cout) {
vector<pair<int64_t, int64_t >> move{{0,  1},
{0,  -1},
{1,  0},
{-1, 0}};
vector<vector<int64_t>> g(30, vector<int64_t>(30));
vector<pair<int64_t, pair<int64_t, int64_t>>> gg;
stack<pair<int64_t, int64_t>> s;
vector<pair<int64_t, int64_t>> res;
for (int i = 0; i < 30; ++i)
for (int j = 0; j < 30; ++j) {
cin >> g[i][j];
gg.emplace_back(g[i][j], make_pair(i, j));
}
sort(gg.begin(), gg.end(), [](pair<int64_t, pair<int64_t, int64_t>> p, pair<int64_t, pair<int64_t, int64_t>> pp) {
return p.first > pp.first;
});

for (const auto &data : gg) {
int64_t i = data.second.first;
int64_t j = data.second.second;
if (g[i][j] == 0) continue;
s.push(make_pair(i, j));
while (!s.empty()) {
auto p = s.top();
s.pop();
int64_t x = p.first;
int64_t y = p.second;
if (g[i][j] == 0) continue;
g[x][y]--;
res.emplace_back(x, y);
for (const auto &item : move) {
int64_t next_x = x + item.first;
int64_t next_y = y + item.second;
if (next_x < 0 || next_x >= 30 || next_y < 0 || next_y >= 30)continue;
if (g[x][y] == 0) continue;
if (g[x][y] != g[next_x][next_y]) continue;
s.push(make_pair(next_x, next_y));
}
if (s.empty() && g[i][j] != 0) {
s.push(make_pair(i, j));
}
}
}
for (const auto &item : res) {
cout << item.first + 1 << " " << item.second + 1 << endl;
}
}
};

int main() {
a solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
```

#### Submission Info

Submission Time 2020-03-30 01:04:24+0900 A - 高橋君の山崩しゲーム T_M C++14 (GCC 5.4.1) 743316 2116 Byte AC 79 ms 1420 KB

#### Judge Result

Set Name Score / Max Score Test Cases