답안 #398518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398518 2021-05-04T12:57:02 Z model_code Peru (RMI20_peru) C++17
100 / 100
157 ms 57724 KB
/**
* user:  ivan-df9
* fname: Tudor
* lname: Ivan
* task:  Peru
* score: 100.0
* date:  2020-12-03 13:09:25.222712
*/
#include "peru.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 2500005;
long long dp[N];
const long long MOD = 1e9 + 7;
struct dqueelem{
  int i;
  long long dpi;
  long long dmin;
};
deque<dqueelem> dq;

bool indeq[N];

/*inline void addmn(int i, int val){
  if(indeq[i] == true)
    return;
  while(mndq.size() && (indeq[mndq.back().i] == false)){
    mndq.pop_back();
  }
  if(mndq.size() == 0 || mndq.back().dpi > val)
    mndq.push_back({i, val}), indeq[i] =true;

}*/
inline void ppbk(){
  indeq[dq.back().i] = 0;
  dq.pop_back();
}

inline void addbk(int i, int* v){
  if(dq.size() == 0){
    dq.push_back({i, LLONG_MAX, LLONG_MAX});
    return;
  }
  long long dpfr = dp[dq.back().i];
  dqueelem x({i, dpfr + v[i], min(dpfr + v[i], dq.back().dmin)});
  dq.push_back(x);
}
inline void ppfrt(){

  if(dq.size()){
    indeq[dq.front().i] = false;
    dq.pop_front();
  }
  if(dq.size()){
    long long dqf = dq.front().dpi;
    dq.front().dpi = LLONG_MAX;
    dq.front().dmin = LLONG_MAX;
    for(int i=1;i<dq.size();i++){
      if(dq[i].dpi <= dqf)
        break;
      dq[i].dmin = min(dq[i].dpi, dq[i-1].dmin);
    }
    indeq[dq.front().i] = false;
  }
}
int solve(int n, int k, int* v){
  for(int i = 0; i< n ; i++){
    if(dq.size() && i - dq.front().i >= k)
      ppfrt();
    //dbg();
    while(dq.size() && v[i] >= v[dq.back().i])
      ppbk();
    //dbg();
    addbk(i, v);
   // dbg();
    dp[i] = 1LL * v[dq.front().i];
   // for(auto x:dq){
  //    cout<<x.i<<" "<<x.dpi<<" "<<x.dmin<<"\n";
 //   }
  //  cout<<"ok\n";
    if(i - k >= 0 )
      dp[i] += dp[i - k];
   // dbg();
    if(dq.size()){
      dp[i] = min(dp[i], dq.back().dmin);
    }
  }
  long long ans = 0;
  for(int i = 0; i < n; i++){
    ans*=23LL;
    ans%=MOD;
    dp[i]%=MOD;
    ans+=dp[i];
    ans%=MOD;
  }
  dq.clear();
  return ans;
}

Compilation message

peru.cpp: In function 'void ppfrt()':
peru.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<dqueelem>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=1;i<dq.size();i++){
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 22 ms 9548 KB Output is correct
16 Correct 23 ms 9584 KB Output is correct
17 Correct 25 ms 9488 KB Output is correct
18 Correct 26 ms 9524 KB Output is correct
19 Correct 25 ms 9556 KB Output is correct
20 Correct 25 ms 9648 KB Output is correct
21 Correct 26 ms 9532 KB Output is correct
22 Correct 25 ms 9524 KB Output is correct
23 Correct 27 ms 9604 KB Output is correct
24 Correct 25 ms 9496 KB Output is correct
25 Correct 36 ms 9524 KB Output is correct
26 Correct 26 ms 9480 KB Output is correct
27 Correct 25 ms 9488 KB Output is correct
28 Correct 19 ms 9496 KB Output is correct
29 Correct 21 ms 9816 KB Output is correct
30 Correct 21 ms 9592 KB Output is correct
31 Correct 30 ms 9576 KB Output is correct
32 Correct 22 ms 9572 KB Output is correct
33 Correct 29 ms 9536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 9548 KB Output is correct
2 Correct 23 ms 9584 KB Output is correct
3 Correct 25 ms 9488 KB Output is correct
4 Correct 26 ms 9524 KB Output is correct
5 Correct 25 ms 9556 KB Output is correct
6 Correct 25 ms 9648 KB Output is correct
7 Correct 26 ms 9532 KB Output is correct
8 Correct 25 ms 9524 KB Output is correct
9 Correct 27 ms 9604 KB Output is correct
10 Correct 25 ms 9496 KB Output is correct
11 Correct 36 ms 9524 KB Output is correct
12 Correct 26 ms 9480 KB Output is correct
13 Correct 25 ms 9488 KB Output is correct
14 Correct 19 ms 9496 KB Output is correct
15 Correct 21 ms 9816 KB Output is correct
16 Correct 21 ms 9592 KB Output is correct
17 Correct 30 ms 9576 KB Output is correct
18 Correct 22 ms 9572 KB Output is correct
19 Correct 29 ms 9536 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 124 ms 33964 KB Output is correct
35 Correct 132 ms 55860 KB Output is correct
36 Correct 130 ms 55812 KB Output is correct
37 Correct 157 ms 55872 KB Output is correct
38 Correct 119 ms 55836 KB Output is correct
39 Correct 126 ms 55824 KB Output is correct
40 Correct 137 ms 55760 KB Output is correct
41 Correct 142 ms 55768 KB Output is correct
42 Correct 150 ms 55904 KB Output is correct
43 Correct 48 ms 22604 KB Output is correct
44 Correct 94 ms 34772 KB Output is correct
45 Correct 94 ms 34716 KB Output is correct
46 Correct 99 ms 34660 KB Output is correct
47 Correct 153 ms 56968 KB Output is correct
48 Correct 143 ms 57024 KB Output is correct
49 Correct 118 ms 57188 KB Output is correct
50 Correct 115 ms 57696 KB Output is correct
51 Correct 156 ms 57460 KB Output is correct
52 Correct 115 ms 57724 KB Output is correct
53 Correct 136 ms 57652 KB Output is correct
54 Correct 132 ms 55660 KB Output is correct
55 Correct 119 ms 55756 KB Output is correct
56 Correct 134 ms 55656 KB Output is correct
57 Correct 133 ms 55800 KB Output is correct
58 Correct 121 ms 55756 KB Output is correct
59 Correct 145 ms 55724 KB Output is correct
60 Correct 122 ms 55788 KB Output is correct
61 Correct 139 ms 57548 KB Output is correct
62 Correct 154 ms 57528 KB Output is correct
63 Correct 137 ms 57504 KB Output is correct