AtCoder Beginner Contest 060 の A/B/C 問題の解法 #ABC060
2024-01-25AtCoder Beginner Contest 060 の A/B/C 問題の解法。
実装はこちら atcoder/abc/001-100/060 · michimani/atcoder
A - Shiritori
#include <iostream>
using namespace std;
int main()
{
string a, b, c;
cin >> a >> b >> c;
if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}
提出 #49652307 - AtCoder Beginner Contest 060
B - Choose Integers
整数
今回の問題では
YES
となるような入力についてはどこかのタイミングで NO
となるような入力については、 NO
となる。
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using ui = unsigned int;
int main()
{
ui a, b, c;
cin >> a >> b >> c;
map<ui, ui> rm;
vector<ui> rv;
ui x = 1;
ui pr = 0;
bool exists = false;
while (true)
{
ui r = (a * x - c) % b;
if (r == 0)
{
cout << "YES" << endl;
return 0;
}
if (rm.count(r) > 0)
{
if (exists && rv[rm[r] - 1] == pr)
{
cout << "NO" << endl;
return 0;
}
exists = true;
}
else
{
exists = false;
}
rv.push_back(r);
rm[r] = rv.size() - 1;
pr = r;
x++;
}
return 0;
}
提出 #49652242 - AtCoder Beginner Contest 060
C - Sentou
シャワーが出ている状態でスイッチを押すと、既に出ているシャワーの残り時間を無視してその時点から
スイッチが押されていない状態では、
#include <iostream>
#include <cmath>
using namespace std;
using ui = unsigned int;
int main()
{
ui n, t;
cin >> n >> t;
ui ans = t;
ui prev = 0;
for (ui i = 0; i < n; i++)
{
ui tt;
cin >> tt;
ans += min(t, tt - prev);
prev = tt;
}
cout << ans << endl;
return 0;
}
提出 #49634392 - AtCoder Beginner Contest 060