답안 #116656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116656 2019-06-13T11:06:25 Z JohnTitor 조교 (CEOI16_popeala) C++11
26 / 100
2000 ms 15096 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Popeala"
int n, t, h;
ll s[20001];
ll x[20001];
string p[51];
int nf[51][20001];
ll nc[51][50001];
ll f[20001];
ll g[20001];
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(t);
    read(h);
    FOR(i, 1, t) read(s[i]);
    FOR(i, 1, t) x[i]=x[i-1]+s[i];
    FOR(i, 1, n){
        cin>>p[i];
        p[i]='0'+p[i];
        nf[i][t]=t+1;
        DFOR(j, t-1, 0) if(p[i][j+1]=='0') nf[i][j]=j+1;
        else nf[i][j]=nf[i][j+1];
    }
    FOR(i, 1, t) f[i]=1e18;
    g[0]=1e18;
    FOR(used, 1, h){
        FOR(i, 0, n) FOR(j, 0, t) nc[i][j]=1e18;
        FFOR(i, 0, t) if(f[i]<1e18){
            int cnt=n;
            vector <int> dt;
            FOR(j, 1, n) dt.pb(nf[j][i]);
            sort(dt.begin(), dt.end());
            reverse(dt.begin(), dt.end());
            int now=i+1;
            while(!dt.empty()){
                while((!dt.empty())&&(dt.back()==now)) dt.pop_back();
                nc[dt.size()][now]=min(nc[dt.size()][now], (ll)(f[i]-x[i]*dt.size()));
                now=dt.back();
            }
        }
        FOR(i, 0, t) f[i]=1e18;
        FOR(c, 0, n){
            FOR(i, 1, t){
                nc[c][i]=min(nc[c][i], nc[c][i-1]);
                f[i]=min(f[i], x[i]*c+nc[c][i]);
            }
        }
        writeln(f[t]);
    }
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:50:17: warning: unused variable 'cnt' [-Wunused-variable]
             int cnt=n;
                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1152 KB Output is correct
2 Correct 38 ms 1144 KB Output is correct
3 Correct 40 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 2304 KB Output is correct
2 Correct 291 ms 2832 KB Output is correct
3 Correct 389 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 41 ms 1152 KB Output is correct
4 Correct 38 ms 1144 KB Output is correct
5 Correct 40 ms 1152 KB Output is correct
6 Correct 221 ms 2304 KB Output is correct
7 Correct 291 ms 2832 KB Output is correct
8 Correct 389 ms 3456 KB Output is correct
9 Correct 576 ms 5532 KB Output is correct
10 Correct 892 ms 7032 KB Output is correct
11 Correct 1617 ms 14584 KB Output is correct
12 Correct 1579 ms 15056 KB Output is correct
13 Execution timed out 2048 ms 15096 KB Time limit exceeded
14 Halted 0 ms 0 KB -