結果

問題 No.5002 stick xor
ユーザー SugarDragon5SugarDragon5
提出日時 2018-05-28 23:50:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 1,000 ms
コード長 3,106 bytes
コンパイル時間 7,633 ms
実行使用メモリ 1,524 KB
スコア 40,893
最終ジャッジ日時 2018-05-28 23:51:09
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
1,520 KB
testcase_01 AC 150 ms
1,520 KB
testcase_02 AC 172 ms
1,524 KB
testcase_03 AC 147 ms
1,520 KB
testcase_04 AC 146 ms
1,524 KB
testcase_05 AC 145 ms
1,520 KB
testcase_06 AC 144 ms
1,520 KB
testcase_07 AC 149 ms
1,516 KB
testcase_08 AC 149 ms
1,520 KB
testcase_09 AC 150 ms
1,524 KB
testcase_10 AC 153 ms
1,520 KB
testcase_11 AC 163 ms
1,524 KB
testcase_12 AC 166 ms
1,524 KB
testcase_13 AC 147 ms
1,524 KB
testcase_14 AC 151 ms
1,524 KB
testcase_15 AC 146 ms
1,524 KB
testcase_16 AC 148 ms
1,524 KB
testcase_17 AC 149 ms
1,524 KB
testcase_18 AC 150 ms
1,524 KB
testcase_19 AC 148 ms
1,524 KB
testcase_20 AC 147 ms
1,520 KB
testcase_21 AC 155 ms
1,524 KB
testcase_22 AC 156 ms
1,520 KB
testcase_23 AC 163 ms
1,524 KB
testcase_24 AC 148 ms
1,524 KB
testcase_25 AC 144 ms
1,520 KB
testcase_26 AC 155 ms
1,520 KB
testcase_27 AC 149 ms
1,520 KB
testcase_28 AC 154 ms
1,520 KB
testcase_29 AC 152 ms
1,524 KB
testcase_30 AC 156 ms
1,524 KB
testcase_31 AC 160 ms
1,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,k;
    cin>>n>>k;
    vi d(k);
    REP(i,k){
        cin>>d[i];
    }
    vs vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    REP(i,k){
        int ma=-INF;
        P p(0,0);
        bool f=false;
        REP(j,n){
            REP(k,n-d[i]){
                int q=0;
                int u=0;
                bool t=vec[j][k]=='0';
                REP(l,d[i]){
                    if(vec[j][k+l]=='1'){
                        q+=3;
                        if(t){
                            u++;
                        }
                        t=false;
                    }else{
                        q-=3;
                        if(!t){
                            u++;
                        }
                        t=true;
                    }
                }
                q-=u;
                if(q>ma){
                    ma=q;
                    p=P(j,k);
                    f=false;
                }
            }
        }
        REP(j,n-d[i]){
            REP(k,n){
                int q=0;
                int u=0;
                bool t=vec[j][k]=='0';
                REP(l,d[i]){
                    if(vec[j+l][k]=='1'){
                        q+=3;
                        if(t){
                            u++;
                        }
                        t=false;
                    }else{
                        q-=3;
                        if(!t){
                            u++;
                        }
                        t=true;
                    }
                }
                q-=u;
                if(q>ma){
                    ma=q;
                    p=P(j,k);
                    f=true;
                }
            }
        }
        if(!f){
            REP(l,d[i]){
                if(vec[p.fi][p.se+l]=='1'){
                    vec[p.fi][p.se+l]='0';
                }else{
                    vec[p.fi][p.se+l]='1';
                }
            }
            cout<<p.fi+1<<" "<<p.se+1<<" "<<p.fi+1<<" "<<p.se+d[i]<<endl;            
        }else{
            REP(l,d[i]){
                if(vec[p.fi+l][p.se]=='1'){
                    vec[p.fi+l][p.se]='0';
                }else{
                    vec[p.fi+l][p.se]='1';
                }
            }
            cout<<p.fi+1<<" "<<p.se+1<<" "<<p.fi+d[i]<<" "<<p.se+1<<endl;                        
        }
    }
    return 0;
}
0