답안 #52842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52842 2018-06-27T04:56:10 Z 김세빈(#1383) 조교 (CEOI16_popeala) C++11
100 / 100
458 ms 17500 KB
#include <bits/stdc++.h>

using namespace std;

vector <int> V[20202];
int R[20202], P[20202];
int K[20202], M[55], dp[55][20202];
int n,m,k;

int main()
{
	int i,j,l,s,e,mid;
	
	scanf("%d%d%d",&n,&m,&k);
	
	for(i=1;i<=m;i++){
		scanf("%d",P+i);
		P[i] += P[i-1];
	}
	
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			scanf("%1d",R+j);
			R[j] += R[j-1];
		}
		
		for(j=1;j<=m;j++){
			for(s=j,e=m;s<=e;){
				mid = s+e>>1;
				if(R[mid] - R[j-1] < mid-j+1) e = mid-1;
				else s = mid+1;				
			}
			V[e+1].push_back(j);
		}
	}
	
	for(i=1;i<=m;i++){
		K[i] = n;
		for(int t: V[i]) K[t] --;
		dp[1][i] = K[1] * P[i];
	}
	
	for(i=2;i<=k;i++){
		for(j=0;j<=n;j++) M[j] = 2e9;
		
		for(j=i;j<=m;j++){
			K[j] = n;
			M[n] = min(M[n], dp[i-1][j-1] - P[j-1] * n);
			for(int t: V[j]) if(t >= i){
				K[t] --;
				M[K[t]] = min(M[K[t]], dp[i-1][t-1] - P[t-1] * K[t]);
			}
			
			dp[i][j] = 2e9;
			for(l=0;l<=n;l++) dp[i][j] = min(dp[i][j], M[l] + P[j] * l);
		}
	}
	
	for(i=1;i<=k;i++) printf("%d\n",dp[i][m]);
	
	return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:29:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     mid = s+e>>1;
           ~^~
popeala.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~
popeala.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",P+i);
   ~~~~~^~~~~~~~~~
popeala.cpp:23:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%1d",R+j);
    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 3 ms 872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1336 KB Output is correct
2 Correct 11 ms 1500 KB Output is correct
3 Correct 12 ms 1500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2244 KB Output is correct
2 Correct 103 ms 2856 KB Output is correct
3 Correct 104 ms 3592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 3 ms 872 KB Output is correct
3 Correct 11 ms 1336 KB Output is correct
4 Correct 11 ms 1500 KB Output is correct
5 Correct 12 ms 1500 KB Output is correct
6 Correct 44 ms 2244 KB Output is correct
7 Correct 103 ms 2856 KB Output is correct
8 Correct 104 ms 3592 KB Output is correct
9 Correct 126 ms 5244 KB Output is correct
10 Correct 190 ms 6908 KB Output is correct
11 Correct 431 ms 13008 KB Output is correct
12 Correct 386 ms 14208 KB Output is correct
13 Correct 458 ms 15212 KB Output is correct
14 Correct 394 ms 16428 KB Output is correct
15 Correct 422 ms 17500 KB Output is correct