LoginSignup
0
0

More than 5 years have passed since last update.

bitsetでオセロ問題を解く

Posted at

お題

回答

実はサンプルしか通れてない、、ご指摘希望

// Othello

#include <bits/stdc++.h>
using namespace std;

int main(){
    const int CAP = 200000;
    int N, Q;
    cin >> N >> Q;

    bitset<CAP> row{0};
    for (int i = 0; i<Q; i++){
        int l, r;
        cin >> l >> r;
        bitset<CAP> mask{pow(2, N - (l-1))-1 - (pow(2, N-r)-1)};
        mask <<= (CAP - N);
        row ^= mask;
    }
    cout << row.to_string().substr(0,N) << endl;
}

感想

  1. bitsetはconst intしか初期化できない、無理やりintをconstにキャストする素人発想はダメだった
  2. ビット演算はやはり紙で試したほうがいい、脳内演算はバグい
  3. substrはiのインデクスからN個のcharを取り出す、pythonなどのiからNまでスラインシングとは違う
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0