ABC157
https://atcoder.jp/contests/abc157
A問題
A問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる
int main(){
int N; cin >> N;
int ans=0;
if (N%2==0) ans=N/2;
else ans=N/2+1;
cout << ans;
}
B問題
B問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる
int main(){
int boo[3][3]; //ここで全ての値をfalseにすることはできない!
int A[3][3]; //int型の記録をすることができるメモリ領域を確保しただけ!
rep(i,3)rep(j,3){
int a; cin >> a;
A[i][j]=a;
boo[i][j]=false; //ここで全ての値をfalseにする!
}
int N; cin >> N;
rep(i,N){
int b; cin >> b;
rep(j,3)rep(k,3){
if (A[j][k]==b) boo[j][k]=true;
}
}
bool ans=false;
// true falseの一致を確かめる時、&&でするのが直感的にいい!
rep(i,3){
if (boo[i][0] && boo[i][1] && boo[i][2]) ans=true;
if (boo[0][i] && boo[1][i] && boo[2][i]) ans=true;
}
if (boo[0][0] && boo[1][1] && boo[2][2]) ans=true;
if (boo[0][2] && boo[1][1] && boo[2][0]) ans=true;
if(ans) cout << "Yes";
else cout << "No";
}
C問題
C問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる
int main(){
int n,m; cin >> n >> m; //桁数n,条件がm個
vector<P> p(m);
//p[i].firstが左から~桁目
//p[i].secondがその桁の数値
rep(i,m) cin >> p[i].first >> p[i].second;
//候補0~999を試す
rep(x,1000){
string s=to_string(x);
int keta=s.length();
if (keta!=n) continue;
bool ok=true;
rep(i,m){
if (s[p[i].first-1]!=p[i].second+'0') ok=false;
}
if(ok){
cout << x << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}