Submission #667722
Source Code Expand
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
class Matrix{
public:
Matrix(int w, int h)
: width(w), height(h), data(w * h) { }
/*
using iterator = typename vector<int>::iterator;
using const_iterator = typename vector<int>::const_iterator;
iterator begin() { data.begin(); }
const_iterator begin() const { data.begin(); }
iterator end() { data.end(); }
const_iterator end() const { data.end(); }
*/
int& operator()(int y, int x) {
if(y >= 0 && x >= 0)
return data[y * width + x];
else dammy; // 領域外の場合はダミーを返す
}
int& operator[](int p) { return data[p]; }
int size() const { return data.size(); }
int pos(int y, int x) { return y * width + x; }
int posx(int p) const { return p % width; }
int posy(int p) const { return p / width; }
int width, height;
bool all_zero(){
for(auto x : data)
if(x != 0)
return false;
return true;
}
private:
vector<int> data;
int dammy = 0;
};
// デバッグ出力
ostream& operator<<(ostream& os, Matrix& m){
if(!os) return os;
for(int i = 0; i < m.height; ++i){
for(int j = 0; j < m.width; ++j)
os << setw(3) << m(i, j);
os << endl;
}
return os;
}
int main(){
const int N = 30;
Matrix matrix(N, N);
// 入力
int tmp;
for(int i = 0; i < matrix.size(); ++i){
cin >> tmp;
matrix[i] = tmp;
}
//int count = 0;
// 1ステップ
while(!matrix.all_zero()){
//++count;
// ステップ1: 一番大きなマスを選択
int p = 0;
int max = -1;
for(int i = 0; i < matrix.size(); ++i){
if(matrix[i] > max){
max = matrix[i];
p = i;
}
}
// ステップ2
--matrix[p];
int y = matrix.posy(p);
int x = matrix.posx(p);
cout << y + 1 << ' ' << x + 1 << endl;
//cout << matrix << endl;
// ステップ3
while(matrix[p] != 0){
bool has_change = false;
// 上、左、右、下の順
if(matrix(y - 1, x) == matrix[p]){
p = matrix.pos(y - 1, x);
has_change = true;
}
else if(matrix(y, x - 1) == matrix[p]){
p = matrix.pos(y, x - 1);
has_change = true;
}
else if(matrix(y, x + 1) == matrix[p]){
p = matrix.pos(y, x + 1);
has_change = true;
}
else if(matrix(y + 1, x) == matrix[p]){
p =matrix. pos(y + 1, x);
has_change = true;
}
// ステップ3の場合のステップ2
if(has_change){ // 変更時のみ
--matrix[p];
y = matrix.posy(p);
x = matrix.posx(p);
//cout << "!! ";
cout << y + 1 << ' ' << x + 1 << endl;
//cout << matrix << endl;
}
else break;
}
}
//cout << count << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - 高橋君の山崩しゲーム |
| User | kmi |
| Language | C++14 (GCC 5.4.1) |
| Score | 0 |
| Code Size | 2712 Byte |
| Status | TLE |
| Exec Time | 10505 ms |
| Memory | 6144 KiB |
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 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | 0 / 100000 | ||||||||||||||||||||
| Status |
|
|
|
|
|
|
|
|
|
|
| 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 | TLE | 10505 ms | 6016 KiB |
| subtask_01_02.txt | TLE | 10505 ms | 5760 KiB |
| subtask_01_03.txt | TLE | 10501 ms | 5888 KiB |
| subtask_01_04.txt | TLE | 10501 ms | 5760 KiB |
| subtask_01_05.txt | TLE | 10501 ms | 6144 KiB |
| subtask_01_06.txt | TLE | 10501 ms | 6016 KiB |
| subtask_01_07.txt | TLE | 10501 ms | 6016 KiB |
| subtask_01_08.txt | TLE | 10505 ms | 6016 KiB |
| subtask_01_09.txt | RE | 663 ms | 256 KiB |
| subtask_01_10.txt | TLE | 10501 ms | 5760 KiB |