結果
| 問題 |
No.5002 stick xor
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2018-05-25 23:33:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.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 / |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#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;
}
どらら