Submission #1077560

# Submission time Handle Problem Language Result Execution time Memory
1077560 2024-08-27T08:01:50 Z ntdaccode K blocks (IZhO14_blocks) C++17
0 / 100
1 ms 604 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
int n,k,f[100010][2],a[100010];
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> k;
  fori(i,1,n) cin >> a[i];
  fori(j,1,k)
  {
    multiset<int> s;
    stack<int> sk;
    fori(i,1,n)
    {
      f[i][j-1&1]+=a[i];
      while(!sk.empty()&&a[sk.top()]<=a[i])
      {
        f[i][j-1&1]=min(f[i][j-1&1],f[sk.top()][j-1&1]-a[sk.top()]+a[i]);
        s.erase(s.find(f[sk.top()][j-1&1]));
        sk.pop();
      }
      s.insert(f[i][j-1&1]);
      f[i][j&1]=*s.begin();
      //cout<< f[i][j&1] << " ";
      sk.push(i);
    }
  }
  cout << f[n][k&1] ;
}



Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:32:13: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   32 |       f[i][j-1&1]+=a[i];
      |            ~^~
blocks.cpp:35:15: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   35 |         f[i][j-1&1]=min(f[i][j-1&1],f[sk.top()][j-1&1]-a[sk.top()]+a[i]);
      |              ~^~
blocks.cpp:35:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   35 |         f[i][j-1&1]=min(f[i][j-1&1],f[sk.top()][j-1&1]-a[sk.top()]+a[i]);
      |                              ~^~
blocks.cpp:35:50: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   35 |         f[i][j-1&1]=min(f[i][j-1&1],f[sk.top()][j-1&1]-a[sk.top()]+a[i]);
      |                                                 ~^~
blocks.cpp:36:37: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   36 |         s.erase(s.find(f[sk.top()][j-1&1]));
      |                                    ~^~
blocks.cpp:39:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   39 |       s.insert(f[i][j-1&1]);
      |                     ~^~
blocks.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -