結果

問題 No.3430 Flip the Grid
コンテスト
ユーザー y_1
提出日時 2026-01-11 14:12:40
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 6,066 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,680 ms
コンパイル使用メモリ 361,996 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2026-01-11 14:12:47
合計ジャッジ時間 6,454 ms
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define MOD 998244353
//#define MOD 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
#define PA() {EXIT_ANS(ans);}
template <typename T> void inline SORT(vector<T> &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline REV(vector<T> &v){reverse(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(vector<T> &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> T inline MAX(vector<T> &v){return *max_element(v.begin(),v.end());}
template <typename T> T inline MIN(vector<T> &v){return *min_element(v.begin(),v.end());}
template <typename T> T inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(vector<T> &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T> bool inline chmin(T &x,T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}
template <typename T> bool inline chmax(T &x,T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template <typename T = long long> vector<T> inline get_vec(int n){
    vector<T> ans(n);
    for(int i = 0; i < n; i++)cin >> ans[i];
    return ans;
}
template <typename T> void inline print_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cout << vec[i];
        if(kaigyou || i == n - 1)cout << '\n';
        else cout << ' ';
    }
    if(!n)cout << '\n';
    return;
}
template <typename T> void inline debug_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cerr << vec[i];
        if(kaigyou || i == n - 1)cerr << '\n';
        else cerr << ' ';
    }
    if(!n)cerr << '\n';
    return;
}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false){
    if(m == -1)m = n - 1;
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        if(!direct)g[v].push_back(u);
    }
    return g;
}
template <typename T> vector<vector<pair<T,int>>> inline get_weighted_graph(int n,int m = -1,bool direct = false){
    if(m == -1)m = n - 1;
    vector<vector<pair<T,int>>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        ll w; cin >> w;
        g[u].push_back(pair(w,v));
        if(!direct)g[v].push_back(pair(w,u));
    }
    return g;
}

template <typename T> vector<pair<T,int>> ococo_runlength(vector<T> const& a){
    vector<pair<T,int>> ans;
    if(a.empty())return ans;
    const int n = (int)a.size();
    int cnt = 0;
    for(int i = 0; i < n - 1; i++){
        cnt++;
        if(a[i] != a[i + 1]){
            ans.push_back(pair(a[i],cnt));
            cnt = 0;
        }
    }
    ans.push_back(pair(a.back(),cnt + 1));
    return ans;
}

vector<pair<char,int>> ococo_string_runlength(string const& s){
    const int n = (int)s.size();
    vector<char> vc(n);
    for(int i = 0; i < n; i++)vc[i] = s[i];
    return ococo_runlength<char>(vc);
}


#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 a.cpp -o o
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h);
    for(int i = 0; i < h; i++)a[i] = get_vec<int>(w);

    for(int j = 0; j < w - 1; j++){
        for(int i = 0; i < h - 1; i++){
            if(a[i][j]){
                a[i][j] ^= 1;
                a[i][j + 1] ^= 1;
                a[i + 1][j] ^= 1;
                a[i + 1][j + 1] ^= 1;
            }
        }
    }


    int ans = 0;
    for(int i = 0; i < h; i++){
        int sm = SUM(a[i]);
        ans += sm;
    }
    int cnt = 0;
    if(a[h - 1][w - 1])cnt++;
    if(a[h - 1][w - 2])cnt++;
    if(a[h - 2][w - 1])cnt++;
    if(a[h - 2][w - 2])cnt++;
    if(cnt == 3)ans -= 2;
    if(cnt == 4)ans -= 4;
    cout << ans << el;
    return;
}

void calc(void){
    int h = 4,w = 4;
    vector<vector<int>> a(h,vector<int>(w,0));

    vector<int> dx = {0,1,0,1};
    vector<int> dy = {0,0,1,1};

    queue<vector<vector<int>>> que; que.push(a);
    set<vector<vector<int>>> pushed; pushed.insert(a);

    while(!que.empty()){
        auto fr = que.front(); que.pop();
        for(int i = 0; i < h - 1; i++){
            for(int j = 0; j < w - 1; j++){
                for(int l = 0; l < 4; l++){
                    fr[i + dx[l]][j + dy[l]] ^= 1;
                }
                if(pushed.find(fr) == pushed.end()){
                    que.push(fr);
                    pushed.insert(fr);
                }
                for(int l = 0; l < 4; l++){
                    fr[i + dx[l]][j + dy[l]] ^= 1;
                }
            }
        }
    }

    for(auto it = pushed.begin(); it != pushed.end(); it++){
        auto temp = *it;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cout << temp[i][j] << ' ';
            }
            cout << el;
        }
        cout << el;
    }
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //calc(); return 0;
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0