Submission #10240437
Source Code Expand
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
int main() {
int h, w, k; cin >> h >> w >> k;
vector<vector<int> > c(w, vector<int>(h));
REP(i, h) REP(j, w) {
char ch; cin >> ch;
c[j][h - 1 - i] = ch - '0';
}
swap(h, w);
int ans = 0;
function<void(vector<vector<int> >&)> solve = [&](vector<vector<int> > &sq) {
int score = 0;
for (int i = 0; ; ++i) {
bool erased = false;
vector<int> pos_y, pos_x, len;
REP(x, w) {
for (int y = 0; y < h;) {
if (x >= sq[y].size()) {
++y;
continue;
}
int z = y + 1;
while (z < h && x < sq[z].size() && sq[z][x] == sq[y][x]) ++z;
if (z - y >= k) {
pos_y.emplace_back(y);
pos_x.emplace_back(x);
len.emplace_back(z - y);
score += (1 << i) * sq[y][x] * (z - y);
erased = true;
}
y = z;
}
}
int n = pos_y.size();
reverse(ALL(pos_y));
reverse(ALL(pos_x));
reverse(ALL(len));
// REP(i, h) {
// REP(j, sq[i].size()) cout << sq[i][j] << ' ';
// cout << endl;
// }
// cout << "-----" << endl;
REP(j, n) {
for (int y = pos_y[j]; y < pos_y[j] + len[j]; ++y) {
sq[y].erase(sq[y].begin() + pos_x[j]);
}
}
if (!erased) break;
}
chmax(ans, score);
};
REP(i, h) REP(j, w) {
vector<vector<int> > sq(c);
sq[i].erase(sq[i].begin() + j);
solve(sq);
}
cout << ans << '\n';
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Falling Stone Game |
User |
emthrm |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
2612 Byte |
Status |
AC |
Exec Time |
13 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
120 / 120 |
180 / 180 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt |
Subtask1 |
sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt, sub1_in6.txt, sub1_in7.txt, sub1_in8.txt |
Subtask2 |
sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt, sub1_in6.txt, sub1_in7.txt, sub1_in8.txt, sub2_in1.txt, sub2_in2.txt, sub2_in3.txt, sub2_in4.txt, sub2_in5.txt, sub2_in6.txt, sub2_in7.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_1.txt |
AC |
1 ms |
256 KB |
sample_2.txt |
AC |
1 ms |
256 KB |
sample_3.txt |
AC |
1 ms |
256 KB |
sample_4.txt |
AC |
2 ms |
256 KB |
sub1_in1.txt |
AC |
1 ms |
256 KB |
sub1_in2.txt |
AC |
1 ms |
256 KB |
sub1_in3.txt |
AC |
1 ms |
256 KB |
sub1_in4.txt |
AC |
1 ms |
256 KB |
sub1_in5.txt |
AC |
1 ms |
256 KB |
sub1_in6.txt |
AC |
1 ms |
256 KB |
sub1_in7.txt |
AC |
1 ms |
256 KB |
sub1_in8.txt |
AC |
1 ms |
256 KB |
sub2_in1.txt |
AC |
1 ms |
256 KB |
sub2_in2.txt |
AC |
1 ms |
256 KB |
sub2_in3.txt |
AC |
1 ms |
256 KB |
sub2_in4.txt |
AC |
2 ms |
256 KB |
sub2_in5.txt |
AC |
3 ms |
256 KB |
sub2_in6.txt |
AC |
5 ms |
256 KB |
sub2_in7.txt |
AC |
13 ms |
256 KB |