답안 #609920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609920 2022-07-28T03:14:15 Z HappyPacMan 조교 (CEOI16_popeala) C++14
100 / 100
491 ms 15292 KB
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9+1;
int dp[51][20001],prefix[51][20001];
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 
	int N,T,S;
	cin >> N >> T >> S;
	int Points[T+1];
	for(int i=1;i<=T;i++){
		cin >> Points[i];
		Points[i] += Points[i-1];
	}
	vector<int> inv[N+1];
	for(int i=1;i<=N;i++){
		string Results;
		cin >> Results;
		for(int j=0;j<T;j++){
			if(Results[j] == '0'){
				inv[i].emplace_back(j+1);
			}
		}
		reverse(inv[i].begin(),inv[i].end());
	}
	vector<int> check[T+1];
	for(int i=1;i<=T;i++){
		check[i].emplace_back(i);
		for(int j=1;j<=N;j++){
			if(!inv[j].empty()){
				check[i].emplace_back(inv[j].back());
			}
		}
		sort(check[i].begin(),check[i].end());
		for(int j=1;j<=N;j++){
			if(!inv[j].empty() && inv[j].back() == i){
				inv[j].pop_back();
			}
		}
	}
	for(int i=0;i<=S;i++){
		for(int j=0;j<=T;j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for(int i=1;i<=S;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=T;k++){
				prefix[j][k] = inf;
			}
		}
		for(int j=i;j<=T;j++){
			for(int k=0;k<check[j].size();k++){
				prefix[N-k][check[j][k]] = min(prefix[N-k][check[j][k]],dp[i-1][j-1]+(N-k)*(Points[check[j][k]]-Points[j-1]));
			}
		}
		for(int j=0;j<=N;j++){
			for(int k=1;k<=T;k++){
				if(prefix[j][k-1] != inf){
					prefix[j][k] = min(prefix[j][k],prefix[j][k-1]+j*(Points[k]-Points[k-1]));
				}
			}
			for(int k=0;k<=T;k++){
				dp[i][k] = min(dp[i][k],prefix[j][k]);
			}
		}
	}
	for(int i=1;i<=S;i++){
		cout << dp[i][T] << "\n";
	}
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    for(int k=0;k<check[j].size();k++){
      |                ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1084 KB Output is correct
2 Correct 12 ms 1072 KB Output is correct
3 Correct 13 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 2132 KB Output is correct
2 Correct 72 ms 2828 KB Output is correct
3 Correct 96 ms 3516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 13 ms 1084 KB Output is correct
4 Correct 12 ms 1072 KB Output is correct
5 Correct 13 ms 980 KB Output is correct
6 Correct 53 ms 2132 KB Output is correct
7 Correct 72 ms 2828 KB Output is correct
8 Correct 96 ms 3516 KB Output is correct
9 Correct 146 ms 5212 KB Output is correct
10 Correct 199 ms 6660 KB Output is correct
11 Correct 470 ms 13972 KB Output is correct
12 Correct 491 ms 14116 KB Output is correct
13 Correct 470 ms 14236 KB Output is correct
14 Correct 481 ms 15268 KB Output is correct
15 Correct 468 ms 15292 KB Output is correct