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.

AtCoder Beginner Contest 244

Last updated at Posted at 2022-03-21

A - Last Letter

O(1)
A問題は、簡単になりましたね。
N-1のindexの文字を表示。

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    int N;
    string s;
    cin >> N >> s;
    cout << s[N-1] << endl;

    return 0;
} 

残り98分

B - Go Straight and Turn Right

O(N)
方角を保持する変数(cnt)と、移動する方角での移動距離を表す配列(X, Y)を用意。

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
 
int X[4] = {1, 0, -1, 0};
int Y[4] = {0, -1, 0, 1};
 
int main() {
    int N;
    string t;
    cin >> N >> t;
 
    int cnt=0, x=0, y=0;
    rep(i, N){
        if(t[i] == 'S'){
            x += X[cnt];
            y += Y[cnt];
        }else{
            cnt++;
            if(cnt>=4) cnt=0;
        }
    }
    cout << x << ' ' << y << endl;
 
    return 0;
}

残り93分

[トイレ休憩]

ここで腹痛という不運が襲う。

残り88分

C - Yamanote Line Game

O(N)
「この問題はインタラクティブな問題」とのこと。
初めて見ましたが、簡単なコンソールゲームですね。

1、setに必要な要素を全て追加。
2、whileにて終了条件をsetのsizeにする
3、先頭の要素を出力、削除
4、対戦相手の入力を受け取る、削除
5、0を受け取る

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
 
int main() {
    int N;
    set<int> st;
    cin >> N;
    rep(i, 2*N+1) st.insert(i+1);
 
    while(st.size()>0){
        int s =  *st.begin();
        cout << s << endl;
        st.erase(s);
        int t;
        cin >> t;
        st.erase(t);
    }
    int e;
    cin >> e;
 
    return 0;
} 

残り80分

D - Swap Hats

O(3)
10^18はシミュレートできない制約です。
つまり規則性を見つける必要があります。

1、10^18ということは交換終了時は偶数回の交換が行われたパターンである。
2、RGBの全ての色が存在しているので、SiとTiの異なる組み合わせの数は0、2、3のみ出現する
3、異なる組み合わせの数が2の場合、奇数回の交換でしかSiとTiを一致させることはできない

0と3のパターンがYes。
2のパターンはNoです。

C++
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
    string s = "RRR";
    string t = "TTT";

    rep(i, 3) cin >> s[i];
    rep(i, 3) cin >> t[i];

    int cnt=0;
    rep(i, 3) if(s[i] != t[i]) cnt++;

    if(cnt==3 || cnt==0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}  

残り70分

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?