답안 #420618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420618 2021-06-08T12:59:44 Z Nicholas_Patrick Cigle (COI21_cigle) C++17
0 / 100
5 ms 1228 KB
#pragma GCC optimize("O3")
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
 
int main(){
	int n;
	scanf("%d", &n);
	vector<int> d(n);
	for(int& i : d)
		scanf("%d", &i);
	vector<vector<int>> dp(n, vector<int>(n, 0));
	/*
		dp[x][y]
		x: last brick laid
		y: earliest brick in last row
		y≤x
	*/
	for(int i=1; i<n; i++){
		vector<int> suffsum, prefsum;
		for(int j=i; j--;){
			if(suffsum.empty()){
				suffsum.push_back(d[j]);
			}else{
				suffsum.push_back(d[j]+suffsum.back());
			}
		}
		for(int j=i; j<n; j++){
			if(prefsum.empty()){
				prefsum.push_back(d[j]);
			}else{
				prefsum.push_back(d[j]+prefsum.back());
			}
		}
		for(int j=0, k=0, matches=0; j<prefsum.size(); j++){
			while(k+1<suffsum.size() and suffsum[k]<prefsum[j])
				k++;
			if(prefsum[j]==suffsum[k]){
				matches++;
				if(i+j+1<n)
					dp[i+j+1][i]=max(dp[i+j+1][i], dp[i-1][i-k-2]+matches);
			}
		}
		if(i){
			for(int j=0; j<n; j++)
				dp[j][i-1]=max(dp[j][i-1], dp[j][i]);
		}
		for(int j=1; j<n; j++)
			dp[j][i]=max(dp[j][i], dp[j-1][i]);
	}
	printf("%d\n", dp[n-1][n-1]);
}

Compilation message

cigle.cpp: In function 'int main()':
cigle.cpp:36:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(int j=0, k=0, matches=0; j<prefsum.size(); j++){
      |                                ~^~~~~~~~~~~~~~~
cigle.cpp:37:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    while(k+1<suffsum.size() and suffsum[k]<prefsum[j])
      |          ~~~^~~~~~~~~~~~~~~
cigle.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cigle.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d", &i);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -