[C++] AtCoder Beginner Contest 197
04 Apr 2021 | PSAtCoder Beginner Contest 197
풀이
A
A - Rotate
3글자 문자열을 받아서 첫번째 문자를 맨뒤로 옮겨 출력하면 정답.
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc197/tasks/abc197_a
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
for(int i = 1;i<s.length();i++){
cout << s[i];
}
cout << s[0];
return 0;
}
B
B - Visibility
정해진 맵이 H,W 크기로 있다고 할 때 맵 상에서 가로와 세로 일직선으로 쭉 볼 수 있다고 하자
(X,Y) 좌표가 보이는 좌표는 총 몇 군데 인지 계산하는 문제
(X,Y)를 기준으로 상하좌우로 반복문을 돌려 장애물이 나올때 까지 세면 정답
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc197/tasks/abc197_b
ll h, w, x, y;
vector<string> s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> h >> w >> x >> y;
s.resize(h);
rep(i, h) { cin >> s[i]; }
ll ans = -3;
x--;
y--;
for (ll i = x; i < h && s[i][y] != '#'; i++) ans++;
for (ll i = x; i >= 0 && s[i][y] != '#'; i--) ans++;
for (ll j = y; j < w && s[x][j] != '#'; j++) ans++;
for (ll j = y; j >= 0 && s[x][j] != '#'; j--) ans++;
cout << ans;
return 0;
}
C
C - ORXOR
N개의 수를 입력받아 이를 두 그룹으로 나누어 한 그룹은 OR 나머지 그룹은 XOR을 한다고 할 때 최소값을 찾는 문제
N이 최대 20으로 작기 떄문에 모든 경우를 포함해도 시간내로 통과 가능
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tuple<ll, ll, ll> tl3;
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define tc(t) while (t--)
// https://atcoder.jp/contests/abc194/tasks/abc197_c
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
vll a(n);
rep(i, n) { cin >> a[i]; }
ll ans = INT_MAX;
for (int i = 0; i < 1 << (n - 1); i++) {
ll xor_ = 0;
ll or_ = 0;
for (int j = 0; j <= n; j++) {
if (j < n) {
or_ |= a[j];
}
if (j == n || (i >> j & 1)) {
xor_ ^= or_ ;
or_ = 0;
}
}
ans = min(ans, xor_);
}
cout << ans;
return 0;
}