結果

問題 No.5002 stick xor
ユーザー どららどらら
提出日時 2018-05-25 23:33:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 686 ms / 1,000 ms
コード長 2,761 bytes
コンパイル時間 24,318 ms
実行使用メモリ 1,548 KB
スコア 40,769
最終ジャッジ日時 2018-05-25 23:33:43
ジャッジサーバーID
(参考情報)
judge10 /
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 648 ms
1,544 KB
testcase_01 AC 640 ms
1,544 KB
testcase_02 AC 677 ms
1,544 KB
testcase_03 AC 646 ms
1,544 KB
testcase_04 AC 635 ms
1,544 KB
testcase_05 AC 615 ms
1,544 KB
testcase_06 AC 617 ms
1,540 KB
testcase_07 AC 638 ms
1,544 KB
testcase_08 AC 627 ms
1,548 KB
testcase_09 AC 635 ms
1,548 KB
testcase_10 AC 647 ms
1,548 KB
testcase_11 AC 652 ms
1,548 KB
testcase_12 AC 658 ms
1,548 KB
testcase_13 AC 622 ms
1,548 KB
testcase_14 AC 641 ms
1,544 KB
testcase_15 AC 614 ms
1,548 KB
testcase_16 AC 644 ms
1,548 KB
testcase_17 AC 647 ms
1,544 KB
testcase_18 AC 649 ms
1,544 KB
testcase_19 AC 623 ms
1,544 KB
testcase_20 AC 618 ms
1,544 KB
testcase_21 AC 636 ms
1,544 KB
testcase_22 AC 648 ms
1,544 KB
testcase_23 AC 686 ms
1,544 KB
testcase_24 AC 660 ms
1,544 KB
testcase_25 AC 625 ms
1,544 KB
testcase_26 AC 664 ms
1,548 KB
testcase_27 AC 644 ms
1,548 KB
testcase_28 AC 652 ms
1,544 KB
testcase_29 AC 638 ms
1,544 KB
testcase_30 AC 633 ms
1,544 KB
testcase_31 AC 618 ms
1,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

double score(const string& parts, const string& prev, string& next){
  double ret = 0;
  rep(i,parts.size()){
    if(parts[i] == '1'){
      ret += 1.0;
    } else {
      if(prev[i] == '1' && next[i] == '1') ret += 0.5;
      else ret -= 10.0;
    }
  }

  return ret;
}

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> L;
  rep(i,K){
    int l;
    cin >> l;
    L.push_back(l);
  }
  vector<string> A;
  rep(i,N){
    string a;
    cin >> a;
    A.push_back(a);
  }

  int W0 = 0;
  rep(y,N) rep(x,N){
    if(A[y][x] == '0') W0++;
  }


  rep(t, K){
    double best_score = -1e18;
    int best_y = 0, best_x = 0, which = 0;
    rep(y,N){
      rep(x,N){
        if(x+L[t]<N){
          string prev = "";
          string parts = "";
          string next = "";
          rep(i,L[t]){
            if(y-1>=0) prev += A[y-1][x+i];
            parts += A[y][x+i];
            if(y+1<N) next += A[y+1][x+i];
          }
          if(prev.size() == 0) prev = string(parts.size(), '*');
          if(next.size() == 0) next = string(parts.size(), '*');
          double d = score(parts, prev, next);
          if(best_score < d){
            best_score = d;
            best_y = y;
            best_x = x;
            which = 0;
          }
        }
        if(y+L[t]<N){
          string prev = "";
          string parts = "";
          string next = "";
          rep(i,L[t]){
            if(x-1>=0) prev += A[y+i][x-1];
            parts += A[y+i][x];
            if(x+1<N) prev += A[y+i][x+1];
          }
          if(prev.size() == 0) prev = string(parts.size(), '*');
          if(next.size() == 0) next = string(parts.size(), '*');
          double d = score(parts, prev, next);
          if(best_score < d){
            best_score = d;
            best_y = y;
            best_x = x;
            which = 1;
          }
        }
      }
    }

    if(which == 0){
      cout << best_y+1 << " " << best_x+1 << " " << best_y+1 << " " << best_x+L[t] << endl;
      rep(i,L[t]){
        if(A[best_y][best_x+i] == '1') A[best_y][best_x+i] = '0';
        else A[best_y][best_x+i] = '1';
      }
    }else{
      cout << best_y+1 << " " << best_x+1 << " " << best_y+L[t] << " " << best_x+1 << endl;
      rep(i,L[t]){
        if(A[best_y+i][best_x] == '1') A[best_y+i][best_x] = '0';
        else A[best_y+i][best_x] = '1';
      }
    }
  }

  int W1 = 0;
  rep(y,N) rep(x,N){
    if(A[y][x] == '0') W1++;
  }

  cerr << W1 - W0 << endl;

  return 0;
}
0