QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137961 | #1283. Paper-cutting | PetroTarnavskyi# | WA | 84ms | 69984kb | C++17 | 2.3kb | 2023-08-10 19:48:12 | 2023-08-10 19:48:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1 << 20;
string s[N];
string t[N];
int n, m;
void resize(){
VI d2(n);
int dL = 0, dR = 0, mx = 0;
for(int i=0,l=-1,r=-1;i<n;i++)
{
if(i<=r)
d2[i] = min(r-i+1,d2[l+(r-i)+1]);
while(i+d2[i]<n && i-(d2[i]+1)>=0 && s[i+d2[i]] == s[i-(d2[i]+1)]) ++d2[i];
if(i + d2[i] > r)
{
r = i + d2[i] - 1;
l = i - d2[i];
}
if(i - d2[i] == 0 && dL < d2[i]){
dL = d2[i];
mx = max(mx, i);
}
if(i + d2[i] == n && dR < d2[i])
dR = d2[i];
}
if(dL == 0 && dR == 0)
return;
if(dL < dR){
reverse(s, s + n);
resize();
return;
}
FOR(i, 0, n){
if(mx + i >= n){
n = i;
break;
}
s[i] = s[mx + i];
}
// cout << n << " " << m << endl;
//delete rows;
}
void transpose(){
FOR(j, 0, m){
t[j] = "";
FOR(i, 0, n)
t[j] += s[i][j];
}
FOR(i, 0, m)
s[i] = t[i];
swap(n, m);
}
bool ok(int i, int j){
return 0 <= i && i < n && 0 <= j && j < m;
}
int id(int i, int j){
return i * m + j;
}
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
bool used[N];
void dfs(int i, int j){
used[id(i, j)] = 1;
FOR(it, 0, 4){
int ni = i + dx[it];
int nj = j + dy[it];
if(!ok(ni, nj) || used[id(ni, nj)] || s[ni][nj] == '1')
continue;
dfs(ni, nj);
}
}
void solve(){
cin >> n >> m;
FOR(i, 0, n)
cin >> s[i];
FOR(it0, 0, 2){
FOR(it1, 0, 2){
resize();
reverse(s, s + n);
}
transpose();
}
int ans = 0;
FOR(i, 0, n)
FOR(j, 0, m)
if(s[i][j] == '0' && !used[id(i, j)]){
dfs(i, j);
ans++;
}
cout << ans << "\n";
FOR(i, 0, n * m)
used[i] = 0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int te;
cin >> te;
while(te--)
solve();
//cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 69984kb
input:
3 2 5 11001 11001 5 7 1001100 0110011 0101101 0010010 1000000 3 2 11 11 11
output:
1 4 0
result:
ok 3 tokens
Test #2:
score: -100
Wrong Answer
time: 84ms
memory: 69072kb
input:
100000 3 3 010 101 101 4 2 10 10 10 10 4 2 11 00 00 11 7 1 1 0 0 1 1 0 0 6 1 1 0 0 1 1 1 5 2 11 00 00 11 11 10 1 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 0 10 1 1 1 1 1 1 1 1 1 1 0 9 1 0 0 0 0 0 0 1 1 0 1 10 0010000100 7 1 0 0 0 0 0 0 0 4 2 00 00 00 00 7 1 0 1 0 0 0 0 1 10 1 1 0 0 0 0 0 0 0 0 1 9 1 1...
output:
3 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 2 1 1 1 0 1 0 2 1 1 1 1 2 1 0 2 2 2 1 2 1 2 2 1 0 1 1 1 2 1 1 1 1 1 1 2 0 1 1 1 1 1 1 1 1 0 3 2 1 3 1 1 3 1 1 1 2 1 1 1 1 1 3 1 1 2 0 1 1 1 2 2 1 2 1 1 2 2 1 2 2 3 2 1 1 1 1 2 1 1 1 1 1 1 1 1 0 1 2 2 2 1 1 5 1 1 1 2 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 2 2 1 3 1 1 2 1 ...
result:
wrong answer 93rd words differ - expected: '1', found: '2'