답안 #494014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494014 2021-12-13T18:15:09 Z cadmiumsky 조교 (CEOI16_popeala) C++14
0 / 100
15 ms 716 KB
#include <iostream>

using namespace std;
using ll=long long;
const int tmax=20005;

int v[tmax];
int t;

namespace cost {
  ll coef[tmax];
  ll rmq[tmax][14];
  ll sum[tmax];
  #define sum (sum + 1)
  void construct() {
    for(int i=0; i<t; i++)
      sum[i]=sum[i-1]+v[i],rmq[i][0]=coef[i];
    for(int step = 1; step < 14; step++) {
      for(int i = 0; i < t; i++) {
        rmq[i][step]=(rmq[i][step-1]&rmq[i + (1 << step - 1)][step - 1]);
      }
    }
  }
  int cost(int x, int y) {
    int len=y-x+1,step=31-__builtin_clz(len);
    return (sum[y]-sum[x-1])*
           __builtin_popcount(rmq[x][step]&rmq[y - (1 << step) + 1][step]);
  }
};
int dp[tmax],prevdp[tmax];
#define dp (dp+1)
#define prevdp (prevdp+1)

static void solve(int l, int r, int bl, int br) {
  if(l>r)
    return;
  int mid=l+r>>1;
  dp[mid]=tmax*50000;
  int cut=bl;
  for(int i=bl; i<=min(mid-1,br); i++) {
    if(prevdp[i]+cost::cost(i+1,mid)<dp[mid]) {
      dp[mid]=prevdp[i]+cost::cost(i+1,mid);
      cut=i;
    }
  }
  solve(l,mid-1,bl,cut);
  solve(mid+1,r,cut,br);
}

int main() {
  int n,s;
  cin >> n >> t >> s;
  for(int i=0; i<t; i++) {
    cin >> v[i];
    prevdp[i]=0;
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<t; j++) {
      char x;
      cin >> x;
      x-='0';
      cost::coef[j]|=(x<<i);
    }
  }
  cost::construct();
  //cout << cost::cost(0,t-1) <<'\n';
  for(int i = 0; i < s; i++) {
    solve(0,t-1,i-1,t);
    cout << dp[t-1] <<'\n';
    for(int j = 0; j < t; j++)
      prevdp[j]=dp[j];
  }
}

Compilation message

popeala.cpp: In function 'void cost::construct()':
popeala.cpp:20:57: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   20 |         rmq[i][step]=(rmq[i][step-1]&rmq[i + (1 << step - 1)][step - 1]);
      |                                                    ~~~~~^~~
popeala.cpp: In function 'void solve(int, int, int, int)':
popeala.cpp:37:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   int mid=l+r>>1;
      |           ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct