답안 #420446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420446 2021-06-08T11:16:24 Z Nicholas_Patrick Cigle (COI21_cigle) C++17
48 / 100
1000 ms 98376 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)for(int j=y; j>=0; j-=j+1&~j)
		ret=max(ret, dp[i][j]);
	return ret;
}
void upd(int x, int y, int v){
	for(int i=x; i<n; i+=i+1&~i)for(int j=y; j<n; j+=j+1&~j)
		dp[i][j]=max(dp[i][j], 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);
			}
		}
	}
	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)for(int j=y; j>=0; j-=j+1&~j)
      |                        ~^~
cigle.cpp:10:54: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   10 |  for(int i=x; i>=0; i-=i+1&~i)for(int j=y; j>=0; j-=j+1&~j)
      |                                                     ~^~
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)for(int j=y; j<n; j+=j+1&~j)
      |                       ~^~
cigle.cpp:15:52: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   15 |  for(int i=x; i<n; i+=i+1&~i)for(int j=y; j<n; j+=j+1&~j)
      |                                                   ~^~
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: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);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1284 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 37 ms 1260 KB Output is correct
5 Correct 31 ms 1228 KB Output is correct
6 Correct 37 ms 1228 KB Output is correct
7 Correct 7 ms 1228 KB Output is correct
8 Correct 7 ms 1228 KB Output is correct
9 Correct 10 ms 1228 KB Output is correct
10 Correct 7 ms 1288 KB Output is correct
11 Correct 9 ms 1228 KB Output is correct
12 Correct 8 ms 1284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 7 ms 1284 KB Output is correct
22 Correct 8 ms 1228 KB Output is correct
23 Correct 7 ms 1280 KB Output is correct
24 Correct 37 ms 1260 KB Output is correct
25 Correct 31 ms 1228 KB Output is correct
26 Correct 37 ms 1228 KB Output is correct
27 Correct 7 ms 1228 KB Output is correct
28 Correct 7 ms 1228 KB Output is correct
29 Correct 10 ms 1228 KB Output is correct
30 Correct 7 ms 1288 KB Output is correct
31 Correct 9 ms 1228 KB Output is correct
32 Correct 8 ms 1284 KB Output is correct
33 Correct 6 ms 1228 KB Output is correct
34 Correct 7 ms 1228 KB Output is correct
35 Correct 7 ms 1228 KB Output is correct
36 Correct 7 ms 1228 KB Output is correct
37 Correct 7 ms 1280 KB Output is correct
38 Correct 7 ms 1228 KB Output is correct
39 Correct 5 ms 1276 KB Output is correct
40 Correct 4 ms 1228 KB Output is correct
41 Correct 3 ms 1228 KB Output is correct
42 Correct 3 ms 1228 KB Output is correct
43 Correct 3 ms 1228 KB Output is correct
44 Correct 3 ms 1228 KB Output is correct
45 Correct 3 ms 1228 KB Output is correct
46 Correct 3 ms 1228 KB Output is correct
47 Correct 3 ms 1228 KB Output is correct
48 Correct 3 ms 1228 KB Output is correct
49 Correct 3 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 7 ms 1284 KB Output is correct
22 Correct 8 ms 1228 KB Output is correct
23 Correct 7 ms 1280 KB Output is correct
24 Correct 37 ms 1260 KB Output is correct
25 Correct 31 ms 1228 KB Output is correct
26 Correct 37 ms 1228 KB Output is correct
27 Correct 7 ms 1228 KB Output is correct
28 Correct 7 ms 1228 KB Output is correct
29 Correct 10 ms 1228 KB Output is correct
30 Correct 7 ms 1288 KB Output is correct
31 Correct 9 ms 1228 KB Output is correct
32 Correct 8 ms 1284 KB Output is correct
33 Correct 6 ms 1228 KB Output is correct
34 Correct 7 ms 1228 KB Output is correct
35 Correct 7 ms 1228 KB Output is correct
36 Correct 7 ms 1228 KB Output is correct
37 Correct 7 ms 1280 KB Output is correct
38 Correct 7 ms 1228 KB Output is correct
39 Correct 5 ms 1276 KB Output is correct
40 Correct 4 ms 1228 KB Output is correct
41 Correct 3 ms 1228 KB Output is correct
42 Correct 3 ms 1228 KB Output is correct
43 Correct 3 ms 1228 KB Output is correct
44 Correct 3 ms 1228 KB Output is correct
45 Correct 3 ms 1228 KB Output is correct
46 Correct 3 ms 1228 KB Output is correct
47 Correct 3 ms 1228 KB Output is correct
48 Correct 3 ms 1228 KB Output is correct
49 Correct 3 ms 1228 KB Output is correct
50 Execution timed out 1088 ms 98376 KB Time limit exceeded
51 Halted 0 ms 0 KB -