Submission #284878

# Submission time Handle Problem Language Result Execution time Memory
284878 2020-08-28T07:26:54 Z arnold518 Žarulje (COI15_zarulje) C++14
22 / 100
1000 ms 180604 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const int MOD = 1e9+7;

int N, A[MAXN+10], Q;
map<pii, int> dp;

int solve(int l, int r)
{
	if(l==1 && r==N) return 1;
	if(dp.find({l, r})!=dp.end()) return dp[{l, r}];
	int &ret=dp[{l, r}];

	if(l==0) return ret=solve(l, r+1);
	if(r==N) return ret=solve(l-1, r);
	if(A[l-1]<A[r+1]) return ret=solve(l, r+1);
	if(A[l-1]>A[r+1]) return ret=solve(l-1, r);
	return ret=(solve(l-1, r)+solve(l, r+1))%MOD;
}

int main()
{
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++) scanf("%d", &A[i]);

	while(Q--)
	{
		int k;
		scanf("%d", &k);
		printf("%d\n", solve(k, k));
	}
}

Compilation message

zarulje.cpp: In function 'int main()':
zarulje.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%d%d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~
zarulje.cpp:30:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
zarulje.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   35 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 146 ms 25980 KB Output is correct
4 Correct 28 ms 4736 KB Output is correct
5 Correct 11 ms 2304 KB Output is correct
6 Correct 14 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1103 ms 180604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 146 ms 25980 KB Output is correct
4 Correct 28 ms 4736 KB Output is correct
5 Correct 11 ms 2304 KB Output is correct
6 Correct 14 ms 2816 KB Output is correct
7 Execution timed out 1103 ms 180604 KB Time limit exceeded
8 Halted 0 ms 0 KB -