0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC225 チャレンジ結果

Posted at

ABC225結果:AB(3)C3完
今回から後半問題の取り組みも期待してC++でやってみた...が手にまだ馴染んでないようで途中からPythonに切り替えたりとてんやわんやであった.

A:ちょっとした高校数学. 3! = 6 or 3!/2! = 3 or 3!/3! = 1のいずれか.

Distinct_Strings.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    set<char> L;
    string S;
    cin >> S;
    
    for (int i=0;i<3;i++){
        L.insert(S[i]);
    }
    
    int sz = L.size();
    //cout << sz;
    if (sz == 3)
        cout << 6;
    if (sz == 2)
        cout << 3;
    if (sz == 1)
        cout << 1;
}

B:入力されたタイミングでその情報を格納すれば瞬殺だった. だが入力を愚直にvectorに入れ, vectorの要素の重複個数を数え, それがN-1になったとき...とやってるとTLEを喰らいました. B問題でかつC++で書いてTLEは焦りを隠せなかった.

Star_or_Not.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

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

    vector<int> a;
    map<int, int> T;
    for (int i=0;i<N-1;i++){
        int ai, bi;
        cin >> ai >> bi;
        T[ai]++;
        T[bi]++;

        //a.push_back(ai);
        //a.push_back(bi);    
    }

    for (int i=1;i<=N;i++){
        if (T[i] == N-1){
            cout << "Yes" << endl;
            break;
        }
        else if (T[i] >= 2){
            cout << "No" << endl;
            break;
        }
    }
}

C:Bで焦ってC問題は馴染んでるPythonでやることに. やっぱPythonすんげえ楽

Calendar_Validator.py
N, M = list(map(int, input().split()))
B = []
for i in range(N):
    X = list(map(int, input().split()))
    B.append(X)

O = B[0][0]
n = (O - 1) // 7 + 1
m = (O - 1) % 7 + 1

flag = True
C = []
if m + M > 8:
    flag = False
    print("No")

else:
    for i in range(N):
        Y = [O + 7 * i + j for j in range(M)]
        if Y != B[i]:
            flag = False
            print("No")
            break
    
if flag == True:
    print("Yes")

Dは連結リストの考え方そのままやん!!と思いながらもコードに落とせず無念.
レートはちょっと上がってギリギリ茶色になりました.
最近停滞気味なので次こそは!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?