답안 #968122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968122 2024-04-23T07:49:12 Z berr 조교 (CEOI16_popeala) C++17
0 / 100
87 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+30;

int r[N][N];

void solve(){
    int n, t, s; cin >> n >> t >> s;
    vector<int> v(t);
    vector<vector<array<int, 2>>> g(t+1);
    vector dis(t+1, vector(s+1, (int)2e9));
    
    for(auto &i: v) cin >> i;

    vector<string> se(n);

    for(auto &i: se){
        cin >> i;
        int k=i[0]-'0';

        for(int l=1; l<t; l++){
            if(i[l]=='0'){
                if(k){
                    r[l-k][l-1]++;
                } 
                k=0;
            }
            else k++;
        }

        if(k){
            r[t-k][t-1]++;
        }
    } 

    for(int i=t; i>1; i--){
        for(int l=0; l+i-1<t; l++){
            r[l+1][l+i-1]+=r[l][l+i-1];
            r[l][l+i-2]+=r[l][l+i-1];
        }
    }

    for(int i=1; i<t; i++) v[i] += v[i-1];

    for(int i=0; i<t; i++){
        int ek=0;
        if(i>0) ek=v[i-1];

        for(int l=i+1; l<t; l++){

            g[i].push_back({l, (v[l-1]-ek)*r[i][l-1]});
        }
 
        g[i].push_back({t, (v[t-1]-ek)*r[i][t-1]});
    }

    priority_queue<array<int, 3>> pq;

    pq.push({0, 0, 0});
    dis[0][0]=0;
    while(pq.size()){

        auto [cos, ed, v]= pq.top();
        pq.pop();
        cos*=-1; 

        if(cos != dis[v][ed]) continue;

        for(auto [i, c]: g[v]){
            if(cos+c < dis[i][ed+1]){
                dis[i][ed+1]=cos+c;
                pq.push({-(cos+c), (ed+1), i});
            }
        }
    }

    for(int i=1; i<=s; i++) cout<<dis[t][i]<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    freopen("popeala.in", "r", stdin);
    freopen("popeala.out", "w", stdout);

    solve();
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:83:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     freopen("popeala.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:84:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     freopen("popeala.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 66 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 65 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 87 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -