Submission #44759471
Source Code Expand
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
#define lcm(a, b) (a / gcd(a, b) * b) // 最小公倍数
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned int uint;
using namespace std;
// -------------------------------------
char c[2009][2009];
int H, W;
void show() {
// rep(h, H) {
// rep(w, W) {
// cout << c[h][w];
// }
// cout << endl;
// }
}
bool checkh(int h) {
char prev = 0;
int count = 0;
rep (w, W) {
if ( c[h][w] != 0 ) count++;
if ( prev == 0 ) {
if ( c[h][w] != 0 ) prev = c[h][w];
} else {
if ( c[h][w] != 0 ) {
if ( prev != c[h][w] ) return false;
prev = c[h][w];
}
}
}
if ( prev == 0 ) return false;
if ( count < 2 ) return false;
return true;
}
bool checkw(int w) {
char prev = 0;
int count = 0;
rep (h, H) {
if ( c[h][w] != 0 ) count++;
if ( prev == 0 ) {
if ( c[h][w] != 0 ) prev = c[h][w];
} else {
if ( c[h][w] != 0 ) {
if ( prev != c[h][w] ) return false;
prev = c[h][w];
}
}
}
if ( prev == 0 ) return false;
if ( count < 2 ) return false;
return true;
}
int main() {
cin >> H >> W;
rep(h, H) {
string s;
cin >> s;
rep(w, s.length()) {
c[h][w] = s[w];
}
}
// cout << "input----" << endl;
show();
while (true) {
vector<int> markh;
vector<int> markw;
//1
rep(h, H) {
if ( checkh(h) ) markh.pb(h);
}
//2
rep(w, W) {
if ( checkw(w) ) markw.pb(w);
}
// 3
if ( markh.size() == 0 && markw.size() == 0 ) break;
// cout << "-----" << endl;
// cout << "markh: " << markh.size() << ", markw: " << markw.size() << endl;
show();
for(int h : markh) {
rep(w, W) c[h][w] = 0;
}
// cout << "-----hdel" << endl;
show();
for(int w : markw) {
rep(h, H) c[h][w] = 0;
}
// cout << "-----wdel" << endl;
show();
}
int ans = 0;
rep(h, H) {
rep(w, W) {
if ( c[h][w] != 0 ) ans++;
}
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Magical Cookies |
| User | saigo |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 2314 Byte |
| Status | TLE |
| Exec Time | 2210 ms |
| Memory | 7580 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample00.txt, sample01.txt, sample02.txt |
| All | sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample00.txt | AC | 1 ms | 3576 KiB |
| sample01.txt | AC | 2 ms | 3592 KiB |
| sample02.txt | AC | 1 ms | 3464 KiB |
| testcase00.txt | AC | 50 ms | 7500 KiB |
| testcase01.txt | AC | 76 ms | 7376 KiB |
| testcase02.txt | AC | 67 ms | 7580 KiB |
| testcase03.txt | AC | 75 ms | 7320 KiB |
| testcase04.txt | AC | 82 ms | 7416 KiB |
| testcase05.txt | AC | 57 ms | 7376 KiB |
| testcase06.txt | AC | 376 ms | 7372 KiB |
| testcase07.txt | AC | 914 ms | 7452 KiB |
| testcase08.txt | AC | 1271 ms | 7332 KiB |
| testcase09.txt | TLE | 2208 ms | 7184 KiB |
| testcase10.txt | AC | 51 ms | 7448 KiB |
| testcase11.txt | AC | 917 ms | 7464 KiB |
| testcase12.txt | AC | 1695 ms | 7376 KiB |
| testcase13.txt | AC | 1835 ms | 7056 KiB |
| testcase14.txt | TLE | 2208 ms | 7104 KiB |
| testcase15.txt | AC | 51 ms | 7440 KiB |
| testcase16.txt | AC | 830 ms | 7176 KiB |
| testcase17.txt | TLE | 2208 ms | 7188 KiB |
| testcase18.txt | TLE | 2208 ms | 7188 KiB |
| testcase19.txt | TLE | 2210 ms | 7192 KiB |
| testcase20.txt | AC | 66 ms | 7468 KiB |
| testcase21.txt | AC | 1368 ms | 7220 KiB |
| testcase22.txt | TLE | 2208 ms | 7252 KiB |
| testcase23.txt | TLE | 2208 ms | 6952 KiB |
| testcase24.txt | TLE | 2208 ms | 7220 KiB |
| testcase25.txt | TLE | 2207 ms | 7200 KiB |
| testcase26.txt | TLE | 2208 ms | 7216 KiB |
| testcase27.txt | TLE | 2210 ms | 7192 KiB |
| testcase28.txt | TLE | 2208 ms | 7180 KiB |
| testcase29.txt | AC | 77 ms | 7460 KiB |
| testcase30.txt | AC | 75 ms | 7408 KiB |
| testcase31.txt | AC | 76 ms | 7500 KiB |
| testcase32.txt | AC | 77 ms | 7476 KiB |