A - Nigiri
oの数を数えましょう。
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;
cin >> s;
int ans = 0;
rep(i, s.size()){
if(s[i] == 'o') ans++;
}
if(ans % 2 == 0) cout << "even" << endl;
else cout << "odd" << endl;
return 0;
}
B - Blank Bingo
全探索で縦横斜めを探索します。
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 = 5;
vector<string> s(n);
rep(i, n) cin >> s[i];
int ans = 5;
rep(i, n){
int cnt = 0;
rep(j, n){
if(s[i][j] == '.') cnt++;
}
ans = min(ans, cnt);
}
rep(i, n){
int cnt = 0;
rep(j, n){
if(s[j][i] == '.') cnt++;
}
ans = min(ans, cnt);
}
int cnt = 0;
rep(i, n){
if(s[i][i] == '.') cnt++;
}
ans = min(ans, cnt);
cnt = 0;
rep(i, n){
if(s[i][5-i-1] == '.') cnt++;
}
ans = min(ans, cnt);
cout << ans << endl;
return 0;
}
C - Band Count
行の範囲の個数と、列の範囲の個数を別の配列で管理しましょう。
二分探索で回答できます。
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 h, w, n, q;
cin >> h >> w >> n >> q;
vector<int> sw;
vector<int> sh;
rep(i, n){
int r, c;
cin >> r >> c;
sw.push_back(r);
sh.push_back(c);
}
sort(sw.begin(), sw.end());
sort(sh.begin(), sh.end());
rep(i, q){
int query;
cin >> query;
if(query == 1){
int u, d;
cin >> u >> d;
int indexu = lower_bound(sw.begin(), sw.end(), u) - sw.begin();
int indexd = upper_bound(sw.begin(), sw.end(), d) - sw.begin();
cout << indexd - indexu << endl;
}
if(query == 2){
int l, r;
cin >> l >> r;
int indexl = lower_bound(sh.begin(), sh.end(), l) - sh.begin();
int indexr = upper_bound(sh.begin(), sh.end(), r) - sh.begin();
cout << indexr - indexl << endl;
}
}
return 0;
}
C++