結果

問題 No.5002 stick xor
ユーザー sumorusumoru
提出日時 2018-05-26 13:56:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 904 ms / 1,000 ms
コード長 4,161 bytes
コンパイル時間 34,219 ms
実行使用メモリ 1,560 KB
スコア 40,639
最終ジャッジ日時 2018-05-26 13:57:10
ジャッジサーバーID
(参考情報)
judge7 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 903 ms
1,556 KB
testcase_01 AC 903 ms
1,560 KB
testcase_02 AC 903 ms
1,556 KB
testcase_03 AC 903 ms
1,556 KB
testcase_04 AC 903 ms
1,552 KB
testcase_05 AC 903 ms
1,556 KB
testcase_06 AC 903 ms
1,560 KB
testcase_07 AC 903 ms
1,560 KB
testcase_08 AC 903 ms
1,556 KB
testcase_09 AC 903 ms
1,560 KB
testcase_10 AC 904 ms
1,560 KB
testcase_11 AC 903 ms
1,560 KB
testcase_12 AC 904 ms
1,552 KB
testcase_13 AC 903 ms
1,556 KB
testcase_14 AC 903 ms
1,556 KB
testcase_15 AC 903 ms
1,556 KB
testcase_16 AC 903 ms
1,560 KB
testcase_17 AC 904 ms
1,560 KB
testcase_18 AC 903 ms
1,560 KB
testcase_19 AC 903 ms
1,556 KB
testcase_20 AC 902 ms
1,556 KB
testcase_21 AC 903 ms
1,556 KB
testcase_22 AC 903 ms
1,556 KB
testcase_23 AC 903 ms
1,560 KB
testcase_24 AC 903 ms
1,556 KB
testcase_25 AC 903 ms
1,556 KB
testcase_26 AC 903 ms
1,556 KB
testcase_27 AC 903 ms
1,560 KB
testcase_28 AC 903 ms
1,556 KB
testcase_29 AC 903 ms
1,560 KB
testcase_30 AC 903 ms
1,560 KB
testcase_31 AC 903 ms
1,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
#include<sys/time.h>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#define LIMIT 0.9
mt19937 mt;
timeval start;
double elapsed(){
    timeval now;
    gettimeofday(&now, nullptr);
    return (now.tv_sec - start.tv_sec) + (now.tv_usec - start.tv_usec) / 1e6;
}

struct Ans {
    int a, b, c, d;
    friend ostream& operator << (ostream& out, Ans& e) {
        return out << e.a + 1 << ' ' << e.b + 1 << ' ' << e.c + 1 << ' ' << e.d + 1;
    }
};

int main(){
    gettimeofday(&start, nullptr);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> ls(k); cin >> ls;
    vector<string> as(n); cin >> as;
    for(auto& a : as){ for(auto& e : a){ e -= '0'; } }
    vector<Ans> ans(k);
    // vector<pair<int, int>> ps(k);
    // for(int i = 0; i < k; i++){
    //     ps[i] = {ls[i], i};
    // }
    // sort(ps.rbegin(), ps.rend());
    // for(auto p : ps){
    //     int i = p.second;
    for(int i = 0; i < k; i++){
        int maxi = -1;
        for(int y = 0; y < n; y++){
            for(int x = 0; x < n - ls[i]; x++){
                int cnt = 0;
                for(int j = 0; j < ls[i]; j++){
                    cnt += as[y][x + j];
                }
                if(maxi < cnt){
                    maxi = cnt;
                    ans[i] = {y, x, y, x + ls[i] - 1};
                }
            }
        }
        for(int y = 0; y < n - ls[i]; y++){
            for(int x = 0; x < n; x++){
                int cnt = 0;
                for(int j = 0; j < ls[i]; j++){
                    cnt += as[y + j][x];
                }
                if(maxi < cnt){
                    maxi = cnt;
                    ans[i] = {y, x, y + ls[i] - 1, x};
                }
            }
        }
        for(int y = ans[i].a; y <= ans[i].c; y++){
            for(int x = ans[i].b; x <= ans[i].d; x++){
                as[y][x] = !as[y][x];
            }
        }
    }
    while(elapsed() < LIMIT){ for(int _ = 0; _ < 100; _++){
    // for(elapsed() < LIMIT){ for(int i = 0; i < 100; i++){
        int i = mt() % k;
        if(ans[i].a == ans[i].c){
            while(ans[i].d + 1 < n && as[ans[i].a][ans[i].b] && as[ans[i].a][ans[i].d + 1]){
                as[ans[i].a][ans[i].b] = !as[ans[i].a][ans[i].b];
                as[ans[i].a][ans[i].d + 1] = !as[ans[i].a][ans[i].d + 1];
                ans[i].b++; ans[i].d++;
            }
            while(ans[i].b && as[ans[i].a][ans[i].b - 1] && as[ans[i].a][ans[i].d]){
                as[ans[i].a][ans[i].b - 1] = !as[ans[i].a][ans[i].b - 1];
                as[ans[i].a][ans[i].d] = !as[ans[i].a][ans[i].d];
                ans[i].b--; ans[i].d--;
            }
        }
        if(ans[i].b == ans[i].d){
            while(ans[i].c + 1 < n && as[ans[i].a][ans[i].b] && as[ans[i].c + 1][ans[i].b]){
                as[ans[i].a][ans[i].b] = !as[ans[i].a][ans[i].b];
                as[ans[i].c + 1][ans[i].b] = !as[ans[i].c + 1][ans[i].b];
                ans[i].a++; ans[i].c++;
            }
            while(ans[i].a && as[ans[i].a - 1][ans[i].b] && as[ans[i].c][ans[i].b]){
                as[ans[i].a - 1][ans[i].b] = !as[ans[i].a - 1][ans[i].b];
                as[ans[i].c][ans[i].b] = !as[ans[i].c][ans[i].b];
                ans[i].a--; ans[i].c--;
            }
        }
    } }
    for(auto& e : ans){
        cout << e << '\n';
    }
}
0