Submission #782550

# Submission time Handle Problem Language Result Execution time Memory
782550 2023-07-14T04:59:54 Z qwerasdfzxcl 케이크 (JOI13_cake) C++17
10 / 100
1500 ms 14932 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
map<int, ll> mp[300300];
int n, a[300300];

ll dfs(int l, int r, int typ = 0){
	// if (mp[l].find(r)!=mp[l].end()) return mp[l][r];
	ll ret = 0;

	if (l==r){
		if (typ) return ret = a[l];
		return ret = 0;
	}

	if (a[l] > a[r]){
		int nl = l+1;
		if (nl > n) nl = 1;

		return ret = ((typ)?a[l]:0) + dfs(nl, r, typ^1);
	}
	int nr = r-1;
	if (nr < 1) nr = n;

	return ret = ((typ)?a[r]:0) + dfs(l, nr, typ^1);
}

int main(){
	scanf("%d", &n);
	for (int i=1;i<=n;i++) scanf("%d", a+i);

	for (int i=1;i<=n;i++){
		int l = i+1, r = i-1;
		if (l>n) l = 1;
		if (r<1) r = n;
		printf("%lld\n", a[i] + dfs(l, r, 0));
	}
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cake.cpp:31:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 14456 KB Output is correct
2 Correct 50 ms 14472 KB Output is correct
3 Correct 52 ms 14752 KB Output is correct
4 Correct 50 ms 14508 KB Output is correct
5 Correct 48 ms 14420 KB Output is correct
6 Correct 49 ms 14508 KB Output is correct
7 Correct 50 ms 14520 KB Output is correct
8 Correct 48 ms 14532 KB Output is correct
9 Correct 7 ms 14332 KB Output is correct
10 Correct 10 ms 14292 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1593 ms 14932 KB Time limit exceeded
2 Halted 0 ms 0 KB -