1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

競技プログラミングの鉄則

A09 - Winter in ALGO Kingdom

  • 例題かつ難しめだったので解説読みながらAC。咀嚼はできているはず
int main() {
    int H,W,N;
    cin >> H >> W >> N;
    int A[100009], B[100009], C[100009], D[100009];
    int X[1509][1509];
    int Z[1509][1509];

    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }
    for (int i = 1;i <= N; i++) {
        X[A[i]][B[i]] += 1;
        X[C[i] + 1][B[i]] -= 1;
        X[A[i]][D[i] + 1] -= 1;
        X[C[i] + 1][D[i] + 1] += 1;
    }

    for (int i = 0; i <= H; i++) {
        for (int j = 0; j <= W; j++) {
            Z[i][j] = 0;
        }
    }
    // 横方向
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            Z[i][j] = Z[i][j - 1] + X[i][j];
        }
    }
    // 縦方向
    for (int j = 1;j <= W;j++){
        for (int i = 1;i <= H;i++){
            Z[i][j] = Z[i - 1][j] + Z[i][j];
        }        
    }

    for (int i = 1; i <= H;i++){
        for (int j = 1; j <= W;j++){
            cout << Z[i][j] << " ";
        }
        cout << endl;
    }  
}

アルゴ式

正規表現 2-1

  • アルゴ式の教科書には書いていなかったがC++ではバックスラッシュ二つにしないとエスケープを表現できないらしい
int main() {
    string S;
    cin >> S;
    if (regex_search(S, regex("1\\+1"))){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
}

正規表現 2-3

  • ハイフンを後ろのユニットに合わせないとハイフンなしの文字列に対応できない「abcd」みたいな
int main() {
    string S;
    cin >> S;
    if (regex_search(S, regex("^[a-z]+(-[a-z]+)*$"))){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    } 
}

Q7. スイッチクエリ (1)

  • 最初以下の様にSを更新せずにただのAND演算をしてしまってバグり散らかしてた
(S | (1 << x));
  • 修正後
int main() {
    int N,S,Q;
    cin >> N >> S >> Q;
    for (int i = 0;i < Q;i++){
        int flag,x;
        cin >> flag >> x;
        if (flag == 0){
            (S = S | (1 << x));
        }
        if (flag == 1){
            if ((S & (1 << x)) == 0){
                cout << "off" << endl;
            }else{
                cout << "on" << endl;
            }
            
        }
    }
}

※これまでは可能な限り取り組んだ問題を記載していたのですがGWみたいに休日が連なったりすると取り組む問題が多すぎて全部を書いてたらそれだけで時間を使ってしまうので「特筆するものだけ記事に載せる」を徹底します。

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?