0
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?

ABC429の記録

Last updated at Posted at 2025-10-25

AtCoder429の感想と自分が解いたところまでの解説を書いていきます
(今回はA~Bを, python, javaでも書きます)
AtCoder Beginner Contest 429

1.感想

A問題:
簡単だった
1分くらいで解けた
個人的に1番見るエラーだった
B問題:
簡単だった
5分以内に解けた
C問題:
1回ミスしてしまったが簡単だった
D問題:
何すればいいのかもわからなかった
E問題:
とりあえずBFSっぽかった(2回目)

2.結果

書き忘れていましたすみません
568になりました

3.解説

A問題 Too Many Requests

C++での解法

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

int main(){
    int N, M;
    cin >> N >> M;
    
    for (int i = 1; i <= N; i++){
        if (i <= M) cout << "OK" << endl;
        else cout << "Too Many Requests" << endl;
    }
}

pythonでの解法

N, M = map(int, input().split())

for i in range(1, N+1):
    print("OK" if i <= M else "Too Many Requests")

javaでの解法

import java.util.*;

public class Main{
    static Scanner javain = new Scanner(System.in);
    
    public static void main (String[] args){
        int N = javain.nextInt(), M = javain.nextInt();
        for (int i = 1; i <= N; i++){
            System.out.println(i <= M? "OK": "Too Many Requests");
        }
    }
}

B問題 N - 1

c++での解法

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

int main(){
    int N, M, sum = 0;
    cin >> N >> M;
    vector<int> A(N);
    
    for (int &i : A){
        cin >> i;
        sum += i;
    }
    
    for (int i = 0; i < N; i++){
        if (sum-A[i] == M){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}

pythonでの解法

N, M = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
ans = "No"

for i in A:
    if S-i == M:
        ans = "Yes"

print(ans)

javaでの解法

import java.util.*;

public class Main{
    static Scanner javain = new Scanner(System.in);
    
    public static void main (String[] args){
        String ans = "No";
        int N = javain.nextInt(), M = javain.nextInt(), sum = 0;
        int[] A = new int[N];
        
        for (int i = 0; i < N; i++){
            A[i] = javain.nextInt();
            sum += A[i];
        }
        
        for (int i = 0; i < N; i++){
            if (sum-A[i] == M){
                ans = "Yes";
                break;
            }
        }
        
        System.out.println(ans);
    }
}

C問題 Odd One Subsequence

C++での解法

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

int main(){
    ll N, res = 0;
    cin >> N;
    map<ll, ll> count;
    vector<pair<ll, ll>> A;
    
    for (ll _ = 0; _ < N; _++){
        ll a;
        cin >> a;
        count[a]++;
    }
    
    for (auto i : count) A.push_back(i);
    
    for (ll i = 0; i < (ll)A.size(); i++){
        if (A[i].second < 2) continue;
        res += (A[i].second*(A[i].second-1)/2*max(0ll, N-A[i].second));
    }
    
    cout << res << endl;
    return 0;
}
0
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
0
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?