Submission #420452

# Submission time Handle Problem Language Result Execution time Memory
420452 2021-06-08T11:19:04 Z Nicholas_Patrick Cigle (COI21_cigle) C++17
0 / 100
10 ms 1280 KB
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
 
int n;
vector<vector<int>> dp;
int qry(int x, int y){
	int ret=-1000000000;
	for(int i=x; i>=0; i-=i+1&~i)
		ret=max(ret, dp[i][y]);
	return ret;
}
void upd(int x, int y, int v){
	for(int i=x; i<n; i+=i+1&~i)
		dp[i][y]=max(dp[i][y], v);
}
int main(){
	scanf("%d", &n);
	vector<int> d(n);
	for(int& i : d)
		scanf("%d", &i);
	dp.assign(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)
					upd(i+j+1, i, qry(i-1, i-k-2)+matches);
			}
		}
		for(int j=0; j<n; j++)for(int k=i; k<n; k+=k+1&~k)
			dp[j][k]=max(dp[j][k], dp[j][i]);
	}
	int ans=0;
	for(auto& i : dp)
		ans=max(ans, *max_element(i.begin(), i.end()));
	printf("%d\n", ans);
}

Compilation message

cigle.cpp: In function 'int qry(int, int)':
cigle.cpp:10:25: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   10 |  for(int i=x; i>=0; i-=i+1&~i)
      |                        ~^~
cigle.cpp: In function 'void upd(int, int, int)':
cigle.cpp:15:24: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   15 |  for(int i=x; i<n; i+=i+1&~i)
      |                       ~^~
cigle.cpp: In function 'int main()':
cigle.cpp:46:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int j=0, k=0, matches=0; j<prefsum.size(); j++){
      |                                ~^~~~~~~~~~~~~~~
cigle.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    while(k+1<suffsum.size() and suffsum[k]<prefsum[j])
      |          ~~~^~~~~~~~~~~~~~~
cigle.cpp:55:47: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   55 |   for(int j=0; j<n; j++)for(int k=i; k<n; k+=k+1&~k)
      |                                              ~^~
cigle.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cigle.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d", &i);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1280 KB Output is correct
2 Correct 7 ms 1228 KB Output is correct
3 Incorrect 10 ms 1228 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -