답안 #127958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127958 2019-07-10T09:15:30 Z Plurm 조교 (CEOI16_popeala) C++11
17 / 100
2000 ms 4740 KB
#include <bits/stdc++.h>
using namespace std;
char res[64][20005];
int dp[64][20005];
long long cmask[20005];
int qs[20005];
int pts[20005];
long long ST[15][32768];
void build(){
    for(int j = 0; j < 32768; j++){
        ST[0][j] = j < 20005 ? cmask[j] : 0ll;
    }
    for(int i = 1; i < 15; i++){
        for(int j = 0; j + (1 << i) - 1 < 32768; j++){
            ST[i][j] = ST[i-1][j] & ST[i-1][j+(1<<(i-1))];
        }
    }
}
int query(int l, int r){
    int d = r-l+1;
    int k = log2(d);
    return __builtin_popcountll(ST[k][l] & ST[k][r-(1 << k)+1]);
}
int main(){
    int n,t,s;
    scanf("%d%d%d",&n,&t,&s);
    for(int i = 1; i <= t; i++){
        scanf("%d",pts+i);
        qs[i] = qs[i-1] + pts[i];
    }
    for(int i = 0; i < n; i++){
        scanf("%s",res[i]+1);
    }
    for(int i = 1; i <= t; i++){
        long long mask = 0ll;
        for(int j = 0; j < n; j++){
            if(res[j][i] == '1') mask |= 1ll << j;
        }
        cmask[i] = mask;
    }
    build();
    for(int i = 1; i <= s; i++){
        dp[i][0] = 2e9;
        for(int j = 1; j <= t; j++){
            dp[i][j] = 2e9;
            long long mask = cmask[j];
            for(int k = j-1; k >= 0; k--){
                if((i == 1 && k == 0) || i != 1) dp[i][j] = min(dp[i][j], dp[i-1][k] + query(k+1,j) * (qs[j] - qs[k]));
                mask &= cmask[k];
            }
        }
        printf("%d\n",dp[i][t]);
    }
    return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&t,&s);
     ~~~~~^~~~~~~~~~~~~~~~~~~
popeala.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",pts+i);
         ~~~~~^~~~~~~~~~~~
popeala.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",res[i]+1);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3960 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 4536 KB Output is correct
2 Correct 206 ms 4572 KB Output is correct
3 Correct 212 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2053 ms 4740 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3960 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 198 ms 4536 KB Output is correct
4 Correct 206 ms 4572 KB Output is correct
5 Correct 212 ms 4472 KB Output is correct
6 Execution timed out 2053 ms 4740 KB Time limit exceeded
7 Halted 0 ms 0 KB -