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.

Atcorder150 A~C問題

Posted at

Atcorder150
https://atcoder.jp/contests/abc150/tasks

#A問題
image.png

A問題.c++
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int K,X; cin >> K >> X;
    if(500*K>=X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

#B問題
image.png

B問題.c++
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    string S; cin >> S;
    
    int ans=0;
    rep(i,N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout << ans << endl;
    return 0;
}

#C問題
image.png

C問題.c++
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    vector <int> P(N),Q(N);
    rep(i,N) cin >> P[i];
    rep(i,N) cin >> Q[i];
    
    vector<int> a(N);
    rep(i,N) a[i]=i+1; //辞書順で一番小さい配列を作る
    
    map<vector<int>,int> mp;
    do{
        mp[a]=mp.size();
    }while(next_permutation(a.begin(),a.end()));
    
    int ans=abs(mp[P]-mp[Q]);
    cout << ans << endl;
    return 0;
}

#まとめ
・C問題 mapとnext_permutationの使い方がわかった!
配列aに辞書順で一番小さい数を代入すると、next_permutationで並べやすい!

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?