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

ABC212

灰 灰 灰 茶 水 黃 黃 橙

A - Alloy

A == 0B == 0を下に条件分けするだけ
スペルミス注意問題

ABC212_A
int A, B; cin >> A >> B;
if (A == 0) {
    cout << "Silver" << endl;
}
else {
    if (B == 0) 
        cout << "Gold" << endl;
    else 
        cout << "Alloy" << endl;
}

B - Weak Password

弱いパターンが全部同じの10通りと階段状10通りの合わせて20通りしかないのでfor分で回した
9→0は(i + 1) % 10でうまくできる
またもやスペル注意

ABC212_B
int X; cin >> X;
bool b = true;
for (int i = 0 ; i < 10; i++) {
    if (X == i * 1111) b = false;
    int j = (i + 1) % 10;
    int k = (j + 1) % 10;
    int l = (k + 1) % 10;
    if (X == i * 1000 + j * 100 + k * 10 + l) b = false;
}
if (b) 
    cout << "Strong" << endl;
else 
    cout << "Weak" << endl;

C - Min Difference

vectorで値受け取ってソートかけて小さい方から順に尺取法?的な感じで小さい方を優先で増やしていく
どっちかが終われば終了
が、解説見た感じpair使って1つのリストでやったほうが早そう
まだ慣れてない感
Min = min(Min, X);の関数??的なの早めに作りたい

ABC212_C
int N, M; cin >> N >> M;
vector<int> A(N), B(M);
for (auto &x : A) cin >> x;
for (auto &x : B) cin >> x;

sort(all(A));
sort(all(B));

int i = 0, j = 0;
int Min = abs(A[i] - B[j]);
while (true) {
    if (A[i] < B[j]) {
        if (i + 1 < N) {
            i++;
        }
        else break;
    }
    else {
        if (j + 1 < M) {
            j++;
        }
        else break;
    }
    Min = min(Min, abs(A[i] - B[j]));
}

cout << Min << endl;

D - Querying Multiset

よくあるクエリの処理を楽にするタイプの問題
Q=2の全てに足すのは個々に行うのではなく出力するときに合わせて足せばいい
なのでQ=1,Q=3をしてQ=3時にQ=2の合計値を足す
priorily_queueは大きい順なので符号反転して使用

しかしなぜかWR
翌々考えてみると途中でQ=1で追加された値はそれまでのQ=2の恩恵を受けることができない。
なのでQ=1時点でのQ=2の合計を引く必要があった。ので改善

ABC212_D
int64_t Q0; cin >> Q0;
priority_queue<int64_t> Q;
int64_t Sum = 0;
for (int q = 0; q < Q0; q++) {
    int query; cin >> query;
    if (query == 1) {
        int64_t X; cin >> X;
-        Q.push(-X);
+        Q.push(-(X - Sum));
    }
    if (query == 2) {
        int64_t X; cin >> X;
        Sum += X;
    }
    if (query == 3) {
        cout << Sum - Q.top() << endl;
        Q.pop();
    }
}

まとめ

A-Dの茶ディフまで4問を解いた(5問目は水なので今回はなし
久々の割のちゃんとコーディングできたと思う
昔何処かで問題埋めするなら8問制になったABC212からがいいと聞いたのでここからやります
継続重視!
5月7日

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