# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
785292 |
2023-07-17T08:05:59 Z |
반딧불(#10021) |
Raspad (COI17_raspad) |
C++17 |
|
573 ms |
100996 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int xx[]={0,1,0,-1},yy[]={1,0,-1,0};
struct unionFind{
int par[6000002];
void init(int n){
for(int i=1; i<=n; i++) par[i] = i;
}
int find(int x){
if(x==par[x]) return x;
return par[x] = find(par[x]);
}
void merge(int x, int y){
x = find(x), y = find(y);
if(x>y) swap(x, y);
par[y] = x;
}
} dsu;
int n, m;
int arr[100002][52];
int num[100002][52], numCnt;
int XL[6000002], XR[6000002];
ll ans;
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf("%1d", &arr[i][j]);
}
}
for(int i=0; i<=n; i++) for(int j=0; j<=m; j++) num[i][j] = i*(m+1)+j;
for(int i=0; i<=(n+1)*(m+1); i++) XL[i] = 1e9, XR[i] = -1e9;
/// V
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(arr[i][j]) ans += ll(i) * ll(n+1-i);
}
}
/// E
/// ���μ�
for(int i=1; i<=n; i++){
for(int j=1; j<m; j++){
if(arr[i][j] && arr[i][j+1]) ans -= ll(i) * ll(n+1-i);
}
}
/// ���μ�
for(int i=1; i<n; i++){
for(int j=1; j<=m; j++){
if(arr[i][j] && arr[i+1][j]) ans -= ll(i) * ll(n-i);
}
}
/// F
/// ��� �������� dsu
dsu.init((n+1)*(m+1));
/// ���� ��ü�� �ѷ��δ� �⺻ ��������
for(int i=0; i<m; i++) dsu.merge(num[0][i], num[0][i+1]), dsu.merge(num[n][i], num[n][i+1]);
for(int i=0; i<n; i++) dsu.merge(num[i][0], num[i+1][0]), dsu.merge(num[i][m], num[i+1][m]);
/// ������ �߰� ����
/// �־��� ���μ��� ���������� ���μ�
for(int i=1; i<=n; i++) for(int j=1; j<m; j++) if(!(arr[i][j] && arr[i][j+1])) dsu.merge(num[i-1][j], num[i][j]);
/// �־��� ���μ��� ���������� ���μ�
for(int i=1; i<n; i++) for(int j=1; j<=m; j++) if(!(arr[i][j] && arr[i+1][j])) dsu.merge(num[i][j-1], num[i][j]);
/// ���Ἲ�к��� �м�
for(int i=0; i<=n; i++) for(int j=0; j<=m; j++){
int p = dsu.find(num[i][j]);
XL[p] = min(XL[p], i);
XR[p] = max(XR[p], i);
}
for(int i=0; i<=n; i++) for(int j=0; j<=m; j++){
int x = num[i][j];
if(!x || dsu.find(x) != x) continue;
ll L = XL[x], R = XR[x]+1;
ans += L * ll(n+1-R);
}
printf("%lld", ans);
}
Compilation message
raspad.cpp: In function 'int main()':
raspad.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
raspad.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%1d", &arr[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
1252 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
1348 KB |
Output is correct |
10 |
Correct |
4 ms |
1092 KB |
Output is correct |
11 |
Correct |
6 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
5 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
29384 KB |
Output is correct |
2 |
Correct |
185 ms |
59784 KB |
Output is correct |
3 |
Correct |
193 ms |
59800 KB |
Output is correct |
4 |
Correct |
129 ms |
53848 KB |
Output is correct |
5 |
Correct |
53 ms |
18136 KB |
Output is correct |
6 |
Correct |
195 ms |
59780 KB |
Output is correct |
7 |
Correct |
154 ms |
59800 KB |
Output is correct |
8 |
Correct |
140 ms |
47868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
1252 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
1348 KB |
Output is correct |
10 |
Correct |
4 ms |
1092 KB |
Output is correct |
11 |
Correct |
6 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
980 KB |
Output is correct |
13 |
Correct |
5 ms |
1236 KB |
Output is correct |
14 |
Correct |
63 ms |
29384 KB |
Output is correct |
15 |
Correct |
185 ms |
59784 KB |
Output is correct |
16 |
Correct |
193 ms |
59800 KB |
Output is correct |
17 |
Correct |
129 ms |
53848 KB |
Output is correct |
18 |
Correct |
53 ms |
18136 KB |
Output is correct |
19 |
Correct |
195 ms |
59780 KB |
Output is correct |
20 |
Correct |
154 ms |
59800 KB |
Output is correct |
21 |
Correct |
140 ms |
47868 KB |
Output is correct |
22 |
Correct |
378 ms |
71356 KB |
Output is correct |
23 |
Correct |
571 ms |
100812 KB |
Output is correct |
24 |
Correct |
535 ms |
100876 KB |
Output is correct |
25 |
Correct |
508 ms |
100892 KB |
Output is correct |
26 |
Correct |
410 ms |
100872 KB |
Output is correct |
27 |
Correct |
443 ms |
89152 KB |
Output is correct |
28 |
Correct |
466 ms |
89036 KB |
Output is correct |
29 |
Correct |
573 ms |
100996 KB |
Output is correct |
30 |
Correct |
429 ms |
100788 KB |
Output is correct |
31 |
Correct |
444 ms |
100892 KB |
Output is correct |
32 |
Correct |
437 ms |
100868 KB |
Output is correct |
33 |
Correct |
453 ms |
89792 KB |
Output is correct |
34 |
Correct |
490 ms |
90848 KB |
Output is correct |