DISCO presents ディスカバリーチャンネル コードコンテスト2016 本戦

Submission #1100945

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  string t;
  cin >> t;
  int len = (int)t.length();
  vi sep = {0};
  FOR (i, 1, len) {
    if (t[i] != t[i-1]) {
      sep.push_back(i);
    }
  }
  sep.push_back(len);
  int sz = (int)sep.size();
  vi seg(sz, 0);
  FOR (i, 1, sz) {
    seg[i] = sep[i] - sep[i-1];
  }
  ll ans = 1e18;
  int first = 0;
  int last = len;
  rep (i, sz) {
    first += seg[i];
    last -= seg[i]; 
    ll tmp = 0;
    tmp += a * first;
    tmp += b * last;
    int invert = 0;
    int j = sz-1 - i;
    if (i > j) {
      invert += i-1;
      if (t[0] == '1') {
        invert += 1;
      }
    } else {
      invert += j-1;
      if (t[len-1] == '0') {
        invert += 1;
      }
    }

    tmp += c * invert;
    ans = min(ans, tmp);
  }
  printf("%lld\n", ans);

  return 0;
}

Submission

Task問題 C - 01文字列
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 700
Source lengthソースコード長 1759 Byte
File nameファイル名
Exec time実行時間 16 ms
Memory usageメモリ使用量 2292 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt,00_example_03.txt
Subtask1 300 / 300 00_example_01.txt,10_01.txt,10_02.txt,10_03.txt,10_04.txt,10_05.txt,10_06.txt,10_07.txt,10_08.txt,10_09.txt,10_10.txt,10_11.txt,10_12.txt,10_13.txt
All 400 / 400 00_example_01.txt,00_example_02.txt,00_example_03.txt,10_01.txt,10_02.txt,10_03.txt,10_04.txt,10_05.txt,10_06.txt,10_07.txt,10_08.txt,10_09.txt,10_10.txt,10_11.txt,10_12.txt,10_13.txt,20_01.txt,20_02.txt,20_03.txt,20_04.txt,20_05.txt,20_06.txt,20_07.txt,20_08.txt,20_09.txt,20_10.txt,20_11.txt,20_12.txt,20_13.txt,20_14.txt,20_15.txt,20_16.txt,20_17.txt,20_18.txt,20_19.txt,20_20.txt,20_21.txt,20_22.txt,20_23.txt,20_24.txt,20_25.txt,20_26.txt,20_27.txt,20_28.txt,20_29.txt,20_30.txt,20_31.txt,20_32.txt,20_33.txt,20_34.txt,20_35.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 3 ms 256 KB
00_example_02.txt AC 3 ms 256 KB
00_example_03.txt AC 3 ms 256 KB
10_01.txt AC 3 ms 256 KB
10_02.txt AC 3 ms 256 KB
10_03.txt AC 3 ms 256 KB
10_04.txt AC 3 ms 256 KB
10_05.txt AC 3 ms 384 KB
10_06.txt AC 3 ms 256 KB
10_07.txt AC 3 ms 256 KB
10_08.txt AC 3 ms 256 KB
10_09.txt AC 3 ms 256 KB
10_10.txt AC 3 ms 256 KB
10_11.txt AC 3 ms 256 KB
10_12.txt AC 3 ms 256 KB
10_13.txt AC 3 ms 256 KB
20_01.txt AC 12 ms 832 KB
20_02.txt AC 14 ms 1276 KB
20_03.txt AC 15 ms 1276 KB
20_04.txt AC 12 ms 832 KB
20_05.txt AC 13 ms 832 KB
20_06.txt AC 12 ms 832 KB
20_07.txt AC 12 ms 960 KB
20_08.txt AC 12 ms 832 KB
20_09.txt AC 12 ms 832 KB
20_10.txt AC 12 ms 832 KB
20_11.txt AC 7 ms 512 KB
20_12.txt AC 9 ms 576 KB
20_13.txt AC 3 ms 384 KB
20_14.txt AC 3 ms 256 KB
20_15.txt AC 3 ms 256 KB
20_16.txt AC 3 ms 256 KB
20_17.txt AC 10 ms 832 KB
20_18.txt AC 3 ms 256 KB
20_19.txt AC 3 ms 256 KB
20_20.txt AC 3 ms 256 KB
20_21.txt AC 10 ms 576 KB
20_22.txt AC 3 ms 256 KB
20_23.txt AC 4 ms 384 KB
20_24.txt AC 3 ms 256 KB
20_25.txt AC 3 ms 256 KB
20_26.txt AC 3 ms 384 KB
20_27.txt AC 3 ms 256 KB
20_28.txt AC 4 ms 256 KB
20_29.txt AC 3 ms 256 KB
20_30.txt AC 3 ms 384 KB
20_31.txt AC 3 ms 256 KB
20_32.txt AC 8 ms 512 KB
20_33.txt AC 3 ms 256 KB
20_34.txt AC 3 ms 256 KB
20_35.txt AC 16 ms 2292 KB