답안 #924139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924139 2024-02-08T14:15:34 Z JakobZorz 조교 (CEOI16_popeala) C++17
17 / 100
2000 ms 13404 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
 
int n,t,s;
ll pts[20001];
int prev_done[50][20000];
ll done[15][20000];
ll dp[51][20001];
int lg2[20001];

ll get(int l,int r){
    int d=r-l;
    return done[lg2[d]][l]&done[lg2[d]][r-(1<<lg2[d])];
}

void solve(){
    cin>>n>>t>>s;
    for(int i=1;i<=t;i++){
        cin>>pts[i];
        pts[i]+=pts[i-1];
    }
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        for(int j=0;j<t;j++){
            if(str[j]=='1'){
                done[0][j]+=1LL<<i;
                if(j)
                    prev_done[i][j]=prev_done[i][j-1];
                else
                    prev_done[i][j]=-1;
            }else{
                prev_done[i][j]=i;
            }
        }
    }
    
    for(int p=1;p<15;p++){
        for(int i=0;i+(1<<p)<=t;i++){
            done[p][i]=done[p-1][i]&done[p-1][i+(1<<(p-1))];
        }
    }
    
    int lg2r=0;
    for(int i=0;i<20001;i++){
        if((1<<lg2r)*2<i)
            lg2r++;
        lg2[i]=lg2r;
    }
    
    for(int i=0;i<51;i++)
        for(int j=0;j<20001;j++)
            dp[i][j]=1e18;
    
    dp[0][0]=0;
    
    for(int num=1;num<=s;num++){
        for(int i=0;i<=t;i++){
            vector<int>to_check;
            for(int j=i-1;j>=num-1;j--)
                to_check.push_back(j);
            
            for(int j:to_check){
                ll csum=pts[i]-pts[j];
                int ppl_active=__builtin_popcountll(get(j,i));
                dp[num][i]=min(dp[num][i],dp[num-1][j]+csum*ppl_active);
            }
        }
    }
    
    for(int i=0;i<s;i++)
        cout<<dp[i+1][t]<<"\n";
}
 
int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("input.in","r",stdin);freopen("output.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}
 
/*
 
2 3 3
4 3 5
101
110
 
 
0
8
16
 
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 13144 KB Output is correct
2 Correct 52 ms 13068 KB Output is correct
3 Correct 51 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 993 ms 13236 KB Output is correct
2 Correct 1849 ms 13348 KB Output is correct
3 Execution timed out 2041 ms 13404 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 51 ms 13144 KB Output is correct
4 Correct 52 ms 13068 KB Output is correct
5 Correct 51 ms 12892 KB Output is correct
6 Correct 993 ms 13236 KB Output is correct
7 Correct 1849 ms 13348 KB Output is correct
8 Execution timed out 2041 ms 13404 KB Time limit exceeded
9 Halted 0 ms 0 KB -