Submission #331354

# Submission time Handle Problem Language Result Execution time Memory
331354 2020-11-28T05:47:46 Z loilon504 K blocks (IZhO14_blocks) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define fi(i,a,b) for(int i=a; i<=b; i++)
#define fid(i,a,b) for(int i=a; i>=b; i--)
#define VanLoi ""
#define gb(i, j) ((i >> j) & 1)
#define MOD 1000000007
#define N 1000005

using namespace std;

int n, k, a[N], f[105][N], top;

struct pii {
    int F, S;
} q[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen(VanLoi".inp", "r", stdin);
    freopen(VanLoi".out", "w", stdout);
    cin >> n >> k;
    fi(i, 1, k)
        fi(j, 0, n) f[i][j] = 1e9;
    f[1][0] = 0;
    fi(i, 1, n) cin >> a[i], f[1][i] = max(f[1][i - 1], a[i]);
    f[1][0] = 1e9;
    fi(i, 2, k) {
        top = 0;
        q[0].S = 0;
        fi(j, 1, n) {
            int res = f[i - 1][j - 1];
            while (top && a[q[top].S] <= a[j]) {
                res = min(res, q[top].F);
                top--;
            }
            f[i][j] = min(f[i][q[top].S], res + a[j]);
            q[++top] = {res, j};
        }
    }
    cout << f[k][n];
    return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define fi(i,a,b) for(int i=a; i<=b; i++)
#define fid(i,a,b) for(int i=a; i>=b; i--)
#define VanLoi ""
#define gb(i, j) ((i >> j) & 1)
#define MOD 1000000007
#define N 1000005

using namespace std;

int n, k, a[N], f[105][N], top;

struct pii {
    int F, S;
} q[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    fi(i, 1, k)
        fi(j, 0, n) f[i][j] = 1e9;
    f[1][0] = 0;
    fi(i, 1, n) cin >> a[i], f[1][i] = max(f[1][i - 1], a[i]);
    f[1][0] = 1e9;
    fi(i, 2, k) {
        top = 0;
        q[0].S = 0;
        fi(j, 1, n) {
            int res = f[i - 1][j - 1];
            while (top && a[q[top].S] <= a[j]) {
                res = min(res, q[top].F);
                top--;
            }
            f[i][j] = min(f[i][q[top].S], res + a[j]);
            q[++top] = {res, j};
        }
    }
    cout << f[k][n];
    return 0;
}

Compilation message

blocks.cpp:57:5: error: redefinition of 'int n'
   57 | int n, k, a[N], f[105][N], top;
      |     ^
blocks.cpp:12:5: note: 'int n' previously declared here
   12 | int n, k, a[N], f[105][N], top;
      |     ^
blocks.cpp:57:8: error: redefinition of 'int k'
   57 | int n, k, a[N], f[105][N], top;
      |        ^
blocks.cpp:12:8: note: 'int k' previously declared here
   12 | int n, k, a[N], f[105][N], top;
      |        ^
blocks.cpp:57:11: error: redefinition of 'int a [1000005]'
   57 | int n, k, a[N], f[105][N], top;
      |           ^
blocks.cpp:12:11: note: 'int a [1000005]' previously declared here
   12 | int n, k, a[N], f[105][N], top;
      |           ^
blocks.cpp:57:17: error: redefinition of 'int f [105][1000005]'
   57 | int n, k, a[N], f[105][N], top;
      |                 ^
blocks.cpp:12:17: note: 'int f [105][1000005]' previously declared here
   12 | int n, k, a[N], f[105][N], top;
      |                 ^
blocks.cpp:57:28: error: redefinition of 'int top'
   57 | int n, k, a[N], f[105][N], top;
      |                            ^~~
blocks.cpp:12:28: note: 'int top' previously declared here
   12 | int n, k, a[N], f[105][N], top;
      |                            ^~~
blocks.cpp:59:8: error: redefinition of 'struct pii'
   59 | struct pii {
      |        ^~~
blocks.cpp:14:8: note: previous definition of 'struct pii'
   14 | struct pii {
      |        ^~~
blocks.cpp:61:3: error: conflicting declaration 'int q [1000005]'
   61 | } q[N];
      |   ^
blocks.cpp:16:3: note: previous declaration as 'pii q [1000005]'
   16 | } q[N];
      |   ^
blocks.cpp:63:5: error: redefinition of 'int main()'
   63 | int main()
      |     ^~~~
blocks.cpp:18:5: note: 'int main()' previously defined here
   18 | int main()
      |     ^~~~
blocks.cpp: In function 'int main()':
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(VanLoi".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     freopen(VanLoi".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~