A - Decisive Battle
EかWを数えてn / 2 < cntで判定すると答えが出ます。
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 n = s.size();
int cnt = 0;
rep(i, n){
if(s[i] == 'E') cnt++;
}
if(n / 2 < cnt) cout << "East" << endl;
else cout << "West" << endl;
return 0;
}
B - Crop
4方向からシミュレーションしました。
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;
cin >> h >> w;
vector<string> c(h);
rep(i, h) cin >> c[i];
int x1=0, x2=w;
int y1=0, y2=h;
for(int y=0; y<h; y++){
int cnt=0;
for(int x=0; x<w; x++){
if(c[y][x] == '.') cnt++;
}
if(w == cnt) y1++;
else break;
}
for(int y=h-1; y>=0; y--){
int cnt=0;
for(int x=0; x<w; x++){
if(c[y][x] == '.') cnt++;
}
if(w == cnt) y2--;
else break;
}
for(int x=0; x<w; x++){
int cnt=0;
for(int y=0; y<h; y++){
if(c[y][x] == '.') cnt++;
}
if(h == cnt) x1++;
else break;
}
for(int x=w-1; x>=0; x--){
int cnt=0;
for(int y=0; y<h; y++){
if(c[y][x] == '.') cnt++;
}
if(h == cnt) x2--;
else break;
}
for(int y=y1; y<y2; y++){
for(int x=x1; x<x2; x++){
cout << c[y][x];
}
cout << endl;
}
return 0;
}
C - Plumage Palette
データ構造の問題です。
1~m日までの日付を全て探索します。
色が変わる日はmapで判定するとO(1)で判定でき、変更される色を加算、減算します。
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, m;
cin >> n >> m;
map<int, vector<pair<int, int>>> mp;
map<int, int> ans;
rep(i, n){
int a, d, b;
cin >> a >> d >> b;
ans[a]++;
mp[d].emplace_back(a, b);
}
rep(i, m){
if(mp.find(i+1) != mp.end()){
for(auto [a, b]:mp[i+1]){
ans[a]--;
if(ans[a] == 0) ans.erase(a);
ans[b]++;
}
}
cout << ans.size() << endl;
}
return 0;
}
C++