답안 #26323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26323 2017-06-29T08:09:53 Z 김현수(#1102) Raspad (COI17_raspad) C++11
100 / 100
193 ms 87076 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, ll,ll> tp;
const ll N = 100005, M = 55;

ll n, m, ans[N], par[M], b[2][M], cc, ic, uc, cnt;
char ipt[N][M];

vector<tp> qry[N];

ll tf (char I[], ll B[]) {
	for(ll i=1;i<=m;i++) {
		if(I[i] == '1') {
			if(I[i-1] != '1') cc++;
			B[i] = cc;
		}
		else B[i] = 0;
	}
}

ll Find (ll P) {
	if(par[P] == P) return P;
	return par[P] = Find(par[P]);
}

void Union (ll A, ll B, vector<tp> &V) {
	A = Find(A); B = Find(B);
	if(A == B) return;
	if(A > B) swap(A, B);
	par[B] = A;
	cc--;
	if(A <= ic && B <= ic) {
		V.push_back(tp(A, B, cnt));
		cnt = 0;
	}
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;i++) {
		scanf("%s",ipt[i]+1);
	}
	for(ll i=1;i<=n;i++) {
		ans[i] = ans[i-1];
		cc = 0; cnt = 1;
		tf(ipt[i], b[1]);
		ans[i] += cc;
		ic = cc;
		if(i == 1) continue;
		tf(ipt[i-1], b[0]);
		ll lft = i-1; uc = cc - ic;
		for(ll j=1;j<=cc;j++) par[j] = j;
		for(ll j=1;j<=m;j++) {
			if(b[0][j] && b[1][j]) Union(b[0][j], b[1][j], qry[i]);
		}
		for(auto &T : qry[i-1]) {
			ll A, B, C; tie(A, B, C) = T;
			ans[i] += C * (cc - uc);
			uc--; lft -= C; cnt += C;
			Union(A+ic, B+ic, qry[i]);
		}
		ans[i] += lft * (cc - uc);
	}
	ll sum = 0;
	for(ll i=1;i<=n;i++) sum += ans[i];
	printf("%lld\n",sum);
}

Compilation message

raspad.cpp: In function 'll tf(char*, ll*)':
raspad.cpp:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
raspad.cpp: In function 'int main()':
raspad.cpp:41:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&m);
                         ^
raspad.cpp:43:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",ipt[i]+1);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 10516 KB Output is correct
2 Correct 0 ms 10516 KB Output is correct
3 Correct 0 ms 10516 KB Output is correct
4 Correct 0 ms 10516 KB Output is correct
5 Correct 0 ms 10516 KB Output is correct
6 Correct 0 ms 10516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 10516 KB Output is correct
2 Correct 0 ms 10516 KB Output is correct
3 Correct 0 ms 10516 KB Output is correct
4 Correct 0 ms 10516 KB Output is correct
5 Correct 0 ms 10516 KB Output is correct
6 Correct 0 ms 10516 KB Output is correct
7 Correct 3 ms 10516 KB Output is correct
8 Correct 0 ms 10516 KB Output is correct
9 Correct 3 ms 10648 KB Output is correct
10 Correct 0 ms 10912 KB Output is correct
11 Correct 3 ms 10648 KB Output is correct
12 Correct 3 ms 10780 KB Output is correct
13 Correct 3 ms 10648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 10516 KB Output is correct
2 Correct 53 ms 10780 KB Output is correct
3 Correct 76 ms 15268 KB Output is correct
4 Correct 23 ms 10516 KB Output is correct
5 Correct 16 ms 10648 KB Output is correct
6 Correct 53 ms 12232 KB Output is correct
7 Correct 59 ms 20812 KB Output is correct
8 Correct 43 ms 12100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 10516 KB Output is correct
2 Correct 0 ms 10516 KB Output is correct
3 Correct 0 ms 10516 KB Output is correct
4 Correct 0 ms 10516 KB Output is correct
5 Correct 0 ms 10516 KB Output is correct
6 Correct 0 ms 10516 KB Output is correct
7 Correct 3 ms 10516 KB Output is correct
8 Correct 0 ms 10516 KB Output is correct
9 Correct 3 ms 10648 KB Output is correct
10 Correct 0 ms 10912 KB Output is correct
11 Correct 3 ms 10648 KB Output is correct
12 Correct 3 ms 10780 KB Output is correct
13 Correct 3 ms 10648 KB Output is correct
14 Correct 19 ms 10516 KB Output is correct
15 Correct 53 ms 10780 KB Output is correct
16 Correct 76 ms 15268 KB Output is correct
17 Correct 23 ms 10516 KB Output is correct
18 Correct 16 ms 10648 KB Output is correct
19 Correct 53 ms 12232 KB Output is correct
20 Correct 59 ms 20812 KB Output is correct
21 Correct 43 ms 12100 KB Output is correct
22 Correct 113 ms 12496 KB Output is correct
23 Correct 193 ms 33748 KB Output is correct
24 Correct 176 ms 37048 KB Output is correct
25 Correct 106 ms 12628 KB Output is correct
26 Correct 143 ms 49588 KB Output is correct
27 Correct 133 ms 15532 KB Output is correct
28 Correct 166 ms 29392 KB Output is correct
29 Correct 163 ms 15400 KB Output is correct
30 Correct 73 ms 10516 KB Output is correct
31 Correct 183 ms 87076 KB Output is correct
32 Correct 99 ms 48928 KB Output is correct
33 Correct 136 ms 21472 KB Output is correct
34 Correct 153 ms 24244 KB Output is correct