(2020년 9월 5일에 작성한 글입니다.)
Dashboard - Codeforces Round #667 (Div. 3) - Codeforces
codeforces.com
A.
놀랍게도 1분만에 풀었다.
그래서 div3 역시 쉽구나 그런 생각을 했다.
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
int a, b;
cin >> T;
while (T--) {
cin >> a >> b;
if (a > b) {
swap(a, b);
}
cout << (b - a + 9) / 10 << '\n';
}
return 0;
}
B.
모르겠었다.
그래도 좀 생각을 해서 풀었는데
반례를 찾았고, 적용해서 고쳤는데 틀렸다.
그래서 나는... 내 풀이에 확신이 없었기 때문에
풀이가 잘못된 줄 알았다.
근데 나중에 애들한테 물어보니까
풀이는 맞았었다... 구현을 잘못했을 뿐.
틀리면, 일단 구현이 맞는지를 확인해보자.
그 전에, 구현을 완벽하게 하고 제출하는 게 물론 더 중요한거지만.
여튼 정말 아쉬움이 많이 남아.
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
ll A, B, X, Y, N;
ll a, b, x, y, n;
ll ans;
cin >> T;
while (T--) {
cin >> A >> B >> X >> Y >> N;
a = A;
b = B;
x = X;
y = Y;
n = N;
if (a - n >= x) {
a = a - n;
n = 0;
}
else {
n -= a - x;
a = x;
if (b - n >= y) {
b = b - n;
}
else {
b = y;
}
}
ans = a * b;
//값 바꿔서 다시
a = B;
b = A;
x = Y;
y = X;
n = N;
if (a - n >= x) {
a = a - n;
n = 0;
}
else {
n -= a - x;
a = x;
if (b - n >= y) {
b = b - n;
}
else {
b = y;
}
}
ans = min(ans, a * b);
cout << ans << '\n';
}
return 0;
}
C.
마음이 급해져서 이미
B, C, D를 왔다갔다 하는 상태였고
그래서 그 급한 마음을 안고 짜느라
진짜 뭔가 잘 안됐고 시간이 많이 걸렸다.
이걸 짤 때 집중력도 100%가 아니었던 것 같다.
그래서 맞췄긴 했지만 1:30만에 맞췄고 너무 아쉬워.
int gcd(int k, int l)
{
return l ? gcd(l, k % l) : k;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T;
int n, x, y;
int left, right, mid;
int ans_max, ans_d;
int d;
int cnt;
int i;
cin >> T;
while (T--) {
cin >> n >> x >> y;
ans_max = 99999999;
for (d = 1; d <= y - x; d++) {
if ((y - x) % d != 0) {
continue;
}
cnt = (y + d - 1) / d;
if (cnt > n) {
cnt = max(n, (y - x) / d + 1);
}
if (cnt > n) {
continue;
}
if (ans_max > y + (n - cnt) * d) {
ans_max = y + (n - cnt) * d;
ans_d = d;
}
}
for (i = ans_max - ans_d * (n - 1); i <= ans_max; i += ans_d) {
cout << i << ' ';
}
cout << '\n';
}
return 0;
}
D.
어렵다고 생각했는데 생각보다 어렵진 않았던 문제.
생각해보니까, 끝자리가 9일 때 1을 더해서 올림이 되는 경우가 아니면
각 자리의 숫자들의 합은 계속 증가하고, 감소하지 않는다.
그러니까 10의 제곱수 단위로 계속 더해가다가 S보다 작아질 때 멈추면 되는거였다.
이것도 생각보다 어렵지 않았다....
ll getSum(ll n) {
ll ret = 0;
while (n) {
ret += n % 10;
n /= 10;
}
return ret;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc; cin >> tc;
while (tc--) {
ll n, s; cin >> n >> s;
ll ans = 0;
ll digit = 10;
while (getSum(n) > s) {
ll cur = (n % digit) / (digit / 10);
if (cur != 0) {
n += (10 - cur) * (digit / 10);
ans += (10 - cur) * (digit / 10);
}
digit *= 10;
}
cout << ans << '\n';
}
return 0;
}