🔵

【ABC422】AtCoder Beginner Contest 422【C++】

に公開

コンテスト名

AtCoder Beginner Contest 422

コンテストURL

https://atcoder.jp/contests/abc422

開催日

2025/09/07 13:10–14:50


A: Stage Clear

解法

  • 問題文通りに判定する
ABC422A.cpp
#include <iostream>
#include <string>
using namespace std;

int main(){
    string s;
    cin >> s;

    if((s[2]-'0')<8){
        cout << s[0] << s[1] << (s[2]-'0')+1 << endl;
    }else if((s[0]-'0')<8){
        cout << (s[0]-'0')+1 << s[1] << 1 << endl;
    }

    return 0;
}

B: Looped Rope

解法

  • 問題文通りに全探索する
ABC422B.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> G(h);
    for(int i=0; i<h; i++){
        cin >> G[i];
    }

    vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
    bool flag = true;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(G[i][j]=='.'){
                continue;
            }

            int cnt = 0;
            for(int k=0; k<4; k++){
                int nx = i + dx[k], ny = j + dy[k];

                if(nx<0 || nx>=h || ny<0 || ny>=w){
                    continue;
                }

                if(G[nx][ny]=='#'){
                    cnt++;
                }
            }

            if(!(cnt==2 || cnt==4)){
                flag = false;
                break;
            }
        }

        if(!flag){
            break;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

C: AtCoder AAC Contest

解法

  • 求める答えは \min \left( n_a, n_c, \lfloor \frac{n_a + n_b + n_c}{3} \rfloor \right)
ABC422C.cpp
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int t;
    cin >> t;

    while(t--){
        long long int a, b, c;
        cin >> a >> b >> c;

        cout << min({a, c, (a+b+c)/3}) << '\n';
    }

    return 0;
}

Discussion