답안 #1065961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065961 2024-08-19T13:37:30 Z Rafi22 Peru (RMI20_peru) C++14
49 / 100
600 ms 111504 KB
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=2000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
ll mod1=998244353;

const int N=2500007;

//ll DP1[N];

ll DP[N];

int a[N];
vector<pair<int,int>>G[N];

int solve(int n,int k,int* v)
{
	FOR(i,1,n) a[i]=v[i-1];
	a[0]=inf,a[n+1]=inf;
	deque<pair<ll,int>>Q;
	vector<pair<int,int>>X;
	X.pb({inf,0});
	FOR(i,1,n+1)
	{
		int last=-1;
		while(X.back().st<a[i]) 
		{
			if(last!=-1&&i-1-X.back().nd<=k) DP[i-1]=min(DP[i-1],DP[X.back().nd]+last);
			last=X.back().st;
			X.pop_back();
		}
		if(last!=-1&&i-1-X.back().nd<=k) DP[i-1]=min(DP[i-1],DP[X.back().nd]+last);
		ROF(j,i-2,1)
		{
			if(DP[j]<=DP[i-1]) break;
			DP[j]=DP[i-1];
		}
		X.pb({a[i],i});
		if(i==n+1) break;
		DP[i]=infl;
		if(sz(Q)>0&&Q[0].nd<=i-k) Q.pop_front();
		while(sz(Q)>0&&Q.back().st<a[i]) Q.pop_back();
		Q.pb({a[i],i});
		DP[i]=DP[max(0,i-k)]+Q[0].st;
	}
	/*FOR(i,1,n)
	{
		DP1[i]=infl;
		int mx=0;
		ROF(j,i,1)
		{
			if(i-j+1>k) break;
			mx=max(mx,a[j]);
			DP1[i]=min(DP1[i],DP1[j-1]+mx);
		}
	}
	
	FOR(i,1,n) debug(DP[i],DP1[i]);*/
	ll h=0;
	FOR(i,1,n) h=(23*h+DP[i])%mod;
    return (int)h;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 59228 KB Output is correct
2 Correct 24 ms 59228 KB Output is correct
3 Correct 28 ms 59228 KB Output is correct
4 Correct 25 ms 59228 KB Output is correct
5 Correct 24 ms 59212 KB Output is correct
6 Correct 24 ms 59228 KB Output is correct
7 Correct 24 ms 59220 KB Output is correct
8 Correct 24 ms 59160 KB Output is correct
9 Correct 25 ms 59228 KB Output is correct
10 Correct 24 ms 59228 KB Output is correct
11 Correct 25 ms 59220 KB Output is correct
12 Correct 24 ms 59224 KB Output is correct
13 Correct 25 ms 59228 KB Output is correct
14 Correct 25 ms 59224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 59228 KB Output is correct
2 Correct 24 ms 59228 KB Output is correct
3 Correct 28 ms 59228 KB Output is correct
4 Correct 25 ms 59228 KB Output is correct
5 Correct 24 ms 59212 KB Output is correct
6 Correct 24 ms 59228 KB Output is correct
7 Correct 24 ms 59220 KB Output is correct
8 Correct 24 ms 59160 KB Output is correct
9 Correct 25 ms 59228 KB Output is correct
10 Correct 24 ms 59228 KB Output is correct
11 Correct 25 ms 59220 KB Output is correct
12 Correct 24 ms 59224 KB Output is correct
13 Correct 25 ms 59228 KB Output is correct
14 Correct 25 ms 59224 KB Output is correct
15 Correct 43 ms 67920 KB Output is correct
16 Correct 44 ms 67924 KB Output is correct
17 Correct 55 ms 67984 KB Output is correct
18 Correct 49 ms 67668 KB Output is correct
19 Correct 43 ms 67676 KB Output is correct
20 Correct 42 ms 67836 KB Output is correct
21 Correct 49 ms 68116 KB Output is correct
22 Correct 61 ms 68044 KB Output is correct
23 Correct 90 ms 68044 KB Output is correct
24 Correct 60 ms 67924 KB Output is correct
25 Correct 68 ms 68116 KB Output is correct
26 Correct 46 ms 67920 KB Output is correct
27 Correct 43 ms 67972 KB Output is correct
28 Correct 57 ms 67904 KB Output is correct
29 Correct 43 ms 67984 KB Output is correct
30 Correct 45 ms 67920 KB Output is correct
31 Correct 44 ms 67920 KB Output is correct
32 Correct 74 ms 68092 KB Output is correct
33 Correct 42 ms 67924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 67920 KB Output is correct
2 Correct 44 ms 67924 KB Output is correct
3 Correct 55 ms 67984 KB Output is correct
4 Correct 49 ms 67668 KB Output is correct
5 Correct 43 ms 67676 KB Output is correct
6 Correct 42 ms 67836 KB Output is correct
7 Correct 49 ms 68116 KB Output is correct
8 Correct 61 ms 68044 KB Output is correct
9 Correct 90 ms 68044 KB Output is correct
10 Correct 60 ms 67924 KB Output is correct
11 Correct 68 ms 68116 KB Output is correct
12 Correct 46 ms 67920 KB Output is correct
13 Correct 43 ms 67972 KB Output is correct
14 Correct 57 ms 67904 KB Output is correct
15 Correct 43 ms 67984 KB Output is correct
16 Correct 45 ms 67920 KB Output is correct
17 Correct 44 ms 67920 KB Output is correct
18 Correct 74 ms 68092 KB Output is correct
19 Correct 42 ms 67924 KB Output is correct
20 Correct 25 ms 59228 KB Output is correct
21 Correct 24 ms 59228 KB Output is correct
22 Correct 28 ms 59228 KB Output is correct
23 Correct 25 ms 59228 KB Output is correct
24 Correct 24 ms 59212 KB Output is correct
25 Correct 24 ms 59228 KB Output is correct
26 Correct 24 ms 59220 KB Output is correct
27 Correct 24 ms 59160 KB Output is correct
28 Correct 25 ms 59228 KB Output is correct
29 Correct 24 ms 59228 KB Output is correct
30 Correct 25 ms 59220 KB Output is correct
31 Correct 24 ms 59224 KB Output is correct
32 Correct 25 ms 59228 KB Output is correct
33 Correct 25 ms 59224 KB Output is correct
34 Correct 214 ms 110892 KB Output is correct
35 Correct 282 ms 111220 KB Output is correct
36 Correct 241 ms 110900 KB Output is correct
37 Correct 383 ms 110920 KB Output is correct
38 Correct 345 ms 110860 KB Output is correct
39 Correct 477 ms 111040 KB Output is correct
40 Execution timed out 795 ms 111504 KB Time limit exceeded
41 Halted 0 ms 0 KB -