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?

競プロ日記#25/04/18

Last updated at Posted at 2025-04-18

AtCoder

ABC161_A-ABC Swap

  • 特になし
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    int tmp;
    tmp = X;
    X = Y;
    Y = tmp;
    tmp = X;
    X = Z;
    Z = tmp;
    cout << X << " " << Y << " " << Z << endl;
}
  • 解き方がクソ雑魚感満載だけA,Bはとにかく早く解く事に慣れたい

ABC161_B-PopularVote

  • そんなに難しくないのに事故った
int main() {
    long long N,M;
    cin >> N >> M;
    vector<long long> A(N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    sort(A.rbegin(), A.rend());
    for (int i = 0; i < M; i++) {
        if (A[i] >= sum / (4 * M)) {
            continue;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}
  • 愚直に実装したのに2ケースだけWA。こういう場合は何かしらの特殊パターンの考慮漏れを検討するがよくわからない。これだけで7,8分溶かした。
  • 愚直に割り算しているせいで割り切れない場合の切り捨て処理で事故っている?と思い積の形で条件分岐させたら通った。本当は割り算のまま求められるようにロジックを変えるべきかとは思うがM > 1より移行しても不等号の向きが変わらないので移行で済ませた。
if (A[i] >= sum / (4 * M)

if ((4 * M) * A[i] >= sum)
  • 結果として10分くらいかかった。本番だったらと思うと絶望する。こういうしょうもないトラップには気を付ける。

ABC161_C-ReplacingInteger

  • 特になし
int main() {
    long long N,K;
    cin >> N >> K;
    
    long long tmp = N % K;
    long long ans = min(tmp, K - tmp);
    cout << ans << endl;
    return 0;


}

ABC132_A-Fifty-Fifty

  • A問題のくせになかなか時間を使わされた
  1. setに入れてset.size()が2かどうかを確認
  2. 4文字のうち適当な1文字(今回はS[0])の登場回数を文字列Sについて4回のfor文で調べる
  3. 2.で求めた値が2であれば1.と合わせると必然的に2種類の文字が2回ずつ出てくる。
string S;
cin >> S;

int countA = 0;

set<char> Sset;
for (int i = 0; i < 4; i++) {
    Sset.insert(S[i]);
}
if (Sset.size() !=2) {
    cout << "No" << endl;
    return 0;
}
for (int i = 0; i < 4; i++) {
    if (S[i] == S[0]){
        countA++;
    } 
}
if (countA == 2) {
    cout << "Yes" << endl;
    return 0;
}else {
    cout << "No" << endl;
    return 0;
}

ABC132_B-OrdinaryNumber

  • A問題もB問題に引き続き小賢しかった。なんかこの回結構手こずらせてくる...
  • for (int i = 0;i < N - 2;i++)で回してp + iが2番目に大きいかを判定すればよい
int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    int ans = 0;

    for (int i = 0;i < N - 2;i++){
        
        if ((p[i] <= p[i + 1] && p[i + 1] <= p[i + 2]) || (p[i] >= p[i + 1] && p[i + 1] >= p[i + 2])){
            ans++;
            
        }
    }
    cout << ans << endl;
}

ABC132_C-DividetheProblems

  • 何故かC問題が一番簡単。昔のABCは難易度がC<B<Aの順だったのかと疑うくらい簡単
  • 普通にソートして終わり
int main() {
    int N;
    cin >> N;
    
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());

    int K = d[N / 2] - d[N / 2 - 1] ;

    cout << K << endl;
        
}

ABC122_A-DoubleHelix

  • 特になし
int main() {
    char b;
    cin >> b;

    if (b == 'A') {
        cout << "T" << endl;
    } else if (b == 'T') {
        cout << "A" << endl;
    } else if (b == 'C') {
        cout << "G" << endl;
    } else if (b == 'G') {
        cout << "C" << endl;
    }
}

ABC122_B-ATCoder

  • 特になし
int main() {
    string S;
    cin >> S;
    
    int length = S.length(); 
    int tmp = 0;   
    for (int i = 0;i < length;i++){
        int max = 0;
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
                max++;
                for (int j = i + 1;j < length;j++){
                    if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
                    max++;
                    }else{
                        break;
                }
            }
        }
        if (max > tmp){
            tmp = max;
        }
    } 
    cout << tmp << endl;
}        
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?