답안 #284915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284915 2020-08-28T07:57:44 Z arnold518 Žarulje (COI15_zarulje) C++14
22 / 100
1000 ms 31132 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> M;
 
int solve(int l, int r)
{
	while(A[l]!=A[r])
 	{
 		if(l==0) r++;
		else if(r==N+1) l--;
		else if(A[l]<A[r]) r++;
		else if(A[l]>A[r]) l--;
 	}

	if(l==0 && r==N+1) return 1;
	if(M.find({l, r})!=M.end()) return M[{l, r}];
	int &ret=M[{l, 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-1, k+1));
	}
}

Compilation message

zarulje.cpp: In function 'int main()':
zarulje.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%d%d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~
zarulje.cpp:34:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
zarulje.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 13 ms 1792 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 1272 KB Output is correct
2 Execution timed out 1084 ms 31132 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 13 ms 1792 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 48 ms 1272 KB Output is correct
8 Execution timed out 1084 ms 31132 KB Time limit exceeded
9 Halted 0 ms 0 KB -