# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
26310 |
2017-06-29T07:00:58 Z |
까제비(#1110) |
Raspad (COI17_raspad) |
C++14 |
|
443 ms |
142788 KB |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MAX_N = 1e5 + 100, MAX_M = 60;
int N, M, Nr[MAX_N][MAX_M];
int Sum[MAX_N*2][MAX_M*2]; bool Chk[MAX_N*2][MAX_M*2];
int main() {
cin >> N >> M;
REPO(i, N) REPO(j, M) scanf("%1d", &Nr[i][j]);
REPO(i, N) REPO(j, M) {
if(Nr[i][j] == 1) Sum[i*2][j*2]++;
if(j && Nr[i][j] && Nr[i][j-1]) Sum[i*2][j*2-1]--;
if(i && Nr[i][j] && Nr[i-1][j]) Sum[i*2-1][j*2]--;
}
queue<pi> Q; Q.push(pi(0, 0)); Chk[0][0] = true;
while(!Q.empty()) {
int x, y; tie(x, y) = Q.front(); Q.pop();
for(int k=0; k<4; k++) {
int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
if(nx < 0 || ny < 0 || nx > 2*N+1 || ny > 2*M+1) continue;
if(Sum[nx][ny] != 0) continue;
if(Chk[nx][ny]) continue;
Chk[nx][ny] = true;
Q.push(pi(nx, ny));
}
}
ll plusV = 0;
REPO(i, 2*N) REPO(j, 2*M) {
if(Sum[i][j] != 0) continue;
if(Chk[i][j]) continue;
Q.push(pi(i, j)); Chk[i][j] = true;
int maxX = -1, minX = 2*N+1;
while(!Q.empty()) {
int x, y; tie(x, y) = Q.front(); Q.pop();
maxX = max(maxX, x);
minX = min(minX, x);
for(int k=0; k<4; k++) {
int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
if(nx < 0 || ny < 0 || nx > 2*N || ny > 2*M) continue;
if(Sum[nx][ny] != 0) continue;
if(Chk[nx][ny]) continue;
Chk[nx][ny] = true;
Q.push(pi(nx, ny));
}
}
plusV += (minX / 2) * (N - maxX / 2);
}
REPO(i, 2*N) REPO(j, 2*M) {
// printf("%2d ", Sum[i][j]); if(j == 2*M) puts("");
if(i) Sum[i][j] += Sum[i-1][j];
if(j) Sum[i][j] += Sum[i][j-1];
if(i && j) Sum[i][j] -= Sum[i-1][j-1];
}
ll ans = 0;
// for(int i=1; i<=N; i++) for(int j=i; j<=N; j++)
// ans += (Sum[2*j][2*M] - Sum[2*i-1][2*M]);
for(int j=1; j<=N; j++)
ans += 1ll * j * Sum[2*j][2*M];
for(int i=1; i<=N; i++)
ans -= 1ll * (N-i+1) * Sum[2*i-1][2*M];
printf("%lld\n", ans + plusV);
return 0;
}
Compilation message
raspad.cpp: In function 'int main()':
raspad.cpp:22:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
REPO(i, N) REPO(j, M) scanf("%1d", &Nr[i][j]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
142788 KB |
Output is correct |
2 |
Correct |
0 ms |
142788 KB |
Output is correct |
3 |
Correct |
0 ms |
142788 KB |
Output is correct |
4 |
Correct |
0 ms |
142788 KB |
Output is correct |
5 |
Correct |
0 ms |
142788 KB |
Output is correct |
6 |
Correct |
0 ms |
142788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
142788 KB |
Output is correct |
2 |
Correct |
0 ms |
142788 KB |
Output is correct |
3 |
Correct |
0 ms |
142788 KB |
Output is correct |
4 |
Correct |
0 ms |
142788 KB |
Output is correct |
5 |
Correct |
0 ms |
142788 KB |
Output is correct |
6 |
Correct |
0 ms |
142788 KB |
Output is correct |
7 |
Correct |
9 ms |
142788 KB |
Output is correct |
8 |
Correct |
0 ms |
142788 KB |
Output is correct |
9 |
Correct |
13 ms |
142788 KB |
Output is correct |
10 |
Correct |
6 ms |
142788 KB |
Output is correct |
11 |
Correct |
9 ms |
142788 KB |
Output is correct |
12 |
Correct |
9 ms |
142788 KB |
Output is correct |
13 |
Correct |
13 ms |
142788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
142788 KB |
Output is correct |
2 |
Incorrect |
443 ms |
142788 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
142788 KB |
Output is correct |
2 |
Correct |
0 ms |
142788 KB |
Output is correct |
3 |
Correct |
0 ms |
142788 KB |
Output is correct |
4 |
Correct |
0 ms |
142788 KB |
Output is correct |
5 |
Correct |
0 ms |
142788 KB |
Output is correct |
6 |
Correct |
0 ms |
142788 KB |
Output is correct |
7 |
Correct |
9 ms |
142788 KB |
Output is correct |
8 |
Correct |
0 ms |
142788 KB |
Output is correct |
9 |
Correct |
13 ms |
142788 KB |
Output is correct |
10 |
Correct |
6 ms |
142788 KB |
Output is correct |
11 |
Correct |
9 ms |
142788 KB |
Output is correct |
12 |
Correct |
9 ms |
142788 KB |
Output is correct |
13 |
Correct |
13 ms |
142788 KB |
Output is correct |
14 |
Correct |
146 ms |
142788 KB |
Output is correct |
15 |
Incorrect |
443 ms |
142788 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |