結果

問題 No.5002 stick xor
ユーザー ts_ts_
提出日時 2018-05-26 01:52:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 166 ms / 1,000 ms
コード長 4,151 bytes
コンパイル時間 8,843 ms
実行使用メモリ 1,644 KB
スコア 41,609
最終ジャッジ日時 2018-05-26 01:52:35
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
1,640 KB
testcase_01 AC 117 ms
1,640 KB
testcase_02 AC 120 ms
1,644 KB
testcase_03 AC 118 ms
1,644 KB
testcase_04 AC 116 ms
1,644 KB
testcase_05 AC 114 ms
1,644 KB
testcase_06 AC 113 ms
1,640 KB
testcase_07 AC 116 ms
1,640 KB
testcase_08 AC 116 ms
1,640 KB
testcase_09 AC 120 ms
1,640 KB
testcase_10 AC 166 ms
1,640 KB
testcase_11 AC 147 ms
1,640 KB
testcase_12 AC 148 ms
1,640 KB
testcase_13 AC 130 ms
1,640 KB
testcase_14 AC 140 ms
1,644 KB
testcase_15 AC 128 ms
1,640 KB
testcase_16 AC 136 ms
1,644 KB
testcase_17 AC 138 ms
1,640 KB
testcase_18 AC 141 ms
1,640 KB
testcase_19 AC 141 ms
1,644 KB
testcase_20 AC 132 ms
1,644 KB
testcase_21 AC 139 ms
1,640 KB
testcase_22 AC 133 ms
1,640 KB
testcase_23 AC 139 ms
1,640 KB
testcase_24 AC 115 ms
1,640 KB
testcase_25 AC 130 ms
1,640 KB
testcase_26 AC 149 ms
1,644 KB
testcase_27 AC 131 ms
1,644 KB
testcase_28 AC 138 ms
1,644 KB
testcase_29 AC 133 ms
1,644 KB
testcase_30 AC 126 ms
1,640 KB
testcase_31 AC 118 ms
1,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

unsigned long xor128(){
    static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned long t=(x^(x<<11));
    x=y;y=z;z=w;
    return (w=(w^(w >> 19))^(t^(t>>8)));
}
double timeLimit=0.85;
const int64_t CYCLES_PER_SEC=2800000000;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};
const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int n,k,W0;
int L[501];
string s[61];
vector<vector<int> > g(101,vector<int>(101,0)),tg(101,vector<int>(101,0));
vector<pair<pint,pint> > ans,tmp;
pair<pint,pint> calc(int length){
    pair<pint,pint> ret;
    pint best={-1000100010,0};
    int lx,rx,ly,ry;
    //vector<pair<pint,pint> > cand;
    rep(i,n)rep(j,n-length+1){
        pint score={0,0};
        rep(k,length){
            if(g[i][j+k]==1) ++score.first;
            else --score.first;
            if(k>0) score.second+=g[i][j+k-1]==g[i][j+k]?1:-1;
            else if(j+k-1>=0)score.second+=g[i][j+k-1]==g[i][j+k]?-1:1;
            if(i>0) score.second+=g[i][j+k]==g[i-1][j+k]?-1:1;
            if(i<n-1) score.second+=g[i][j+k]==g[i+1][j+k]?-1:1;
        }
        if(best<score){
            ret=make_pair(pint(i+1,j+1),pint(i+1,j+length));
            best=score;
        }
    }
    rep(i,n)rep(j,n-length+1){
        pint score={0,0};
        rep(k,length){
            if(g[j+k][i]==1) ++score.first;
            else --score.first;
            if(g[j+k][i]==1) ++score.first;
            else --score.first;
            if(k>0) score.second+=g[j+k-1][i]==g[j+k][i]?1:-1;
            else if(j+k-1>=0)score.second+=g[j+k-1][i]==g[j+k][i]?-1:1;
            if(i>0) score.second+=g[j+k][i]==g[j+k][i-1]?-1:1;
            if(i<n-1) score.second+=g[j+k][i]==g[j+k][i+1]?-1:1;
        }
        if(best<score){
            ret=make_pair(pint(j+1,i+1),pint(j+length,i+1));
            best=score;
        }
    }
    ly=ret.first.first,lx=ret.first.second,ry=ret.second.first,rx=ret.second.second;
    FOR(i,ly,ry+1)FOR(j,lx,rx+1) g[i-1][j-1]^=1;
    return ret;
}
/*pair<pint,pint> calc2(int length){
    bool flag;
    vector<pair<pint,pint> > cand;
    int cx=0,cy=0;
    rep(i,n)rep(j,n)if(g[i][j]==1){
        cx=j+1,cy=i+1;
        flag=true;
        rep(k,4){
            int ty=i+dy[k],tx=j+dx[k];
            if(ty>=0&&ty<n&&tx>=0&&tx<n&&g[ty][tx]==1) flag=false;
        }
        if(flag) cand.pb(pint(i+1,j+1),pint(i+1,j+1));
    }
    int sz=cand.size();
    if(sz==0){
        g[cy-1][cx-1]^=1;
        return make_pair(pint(cy,cx),pint(cy,cx));
    }
    pair<pint,pint> ret=cand[xor128()%sz];
    int ly=ret.first.first,lx=ret.first.second;
    g[ly-1][lx-1]^=1;
    return ret;
}*/
int get_score(){
    int ret=0;
    rep(i,n)rep(j,n)if(g[i][j]==0) ++ret;
    return ret;
}
int main(){
    Timer timer;
    timer.reset();
    cin>>n>>k;
    rep(i,k) cin>>L[i];
    rep(i,n) cin>>s[i];;
    tmp.resize(k);ans.resize(k);
    rep(i,n)rep(j,n){
        g[i][j]=s[i][j]-'0';
    }
    //tg=g;
    int bestscore=-1000100010;
    pair<pint,pint> ret;
    rep(i,k){
        ret=calc(L[i]);
        ans[i]=ret;
    }
    /*while(timer.get()<timeLimit){
        rep(i,k){
            //if(L[i]<=1) ret=calc2(L[i]);
            ret=calc(L[i]);
            tmp[i]=ret;
            //cout<<ret.first.first<<" "<<ret.first.second<<" "<<ret.second.first<<" "<<ret.second.second<<endl;
        }
        int cur=get_score();
        if(bestscore<cur){
            //cerr<<cur<<endl;
            ans=tmp;bestscore=cur;
        }
        g=tg;
    }*/
    rep(i,k){
        cout<<ans[i].first.first<<" "<<ans[i].first.second<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
    }
    return 0;
}
0