最近プライベートが忙しく、競プロの精進から離れてしまっていましたが、
ABCコンテストだけは欠かさず参加しようと思い参加。
ところが(なれない職場環境で肩に力が入りすぎていたのか)右肩甲骨のあたりの違和感がひどく途中離脱。。
B問題までしか取り組めませんでした、、
A問題 Leftrightarrow
#include <iostream>
#include <vector>
#include <regex>
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; }
else return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; }
return false;
}
int main() {
/*bool isCounting = false, ans = false;
long long cnt_eq = 0;*/
std::string S;
std::cin >> S;
//for (int i = 0; i < S.size(); i++) {
// if (S[i] == '<') {
// isCounting = true;
// cnt_eq = 0;
// }
// else if (S[i] == '=') {
// if (isCounting == true) cnt_eq++;
// else {
// isCounting = false;
// cnt_eq = 0;
// }
// }
// else if (S[i] == '>') {
// if ((isCounting == true) && (0 < cnt_eq)) ans = true;
// else {
// isCounting = false;
// cnt_eq = 0;
// }
// }
// else {
// isCounting = false;
// cnt_eq = 0;
// }
// /*if (S[i] == '=') {
// bool isLeftOk = false;
// for (int l = (i - 1); 0 <= l; l--) if (S[l] == '<') isLeftOk = true;
// if (isLeftOk == false) continue;
// for (int r = (i + 1); r < S.size(); r++) {
// if (S[r] == '>') {
// std::cout << "Yes" << std::endl;
// return 0;
// }
// }
// }*/
//}
//std::cout << "No" << std::endl;
//std::regex reg = std::regex("<*=*>");
//bool ans = std::regex_search(S, reg);
//std::cout << (ans == true ? "Yes" : "No") << std::endl;
bool ans = true;
if (S[0] != '<') ans = false;
for (int i = 1; i < (S.size() - 1); i++) if (S[i] != '=') ans = false;
if (S[S.size() - 1] != '>') ans = false;
std::cout << (ans == true ? "Yes" : "No") << std::endl;
}問題文をよく理解できずペナ食らった。
「頭文字が<」かつ「末尾が>」じゃないとだめなのね。難しく考えすぎた。。
B問題 Integer Division Returns
#include <iostream>
#include <vector>
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; }
else return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; }
return false;
}
int main() {
long long X;
std::cin >> X;
long long ans;
if (0 < X) {
if (X % 10 != 0) ans = (X / 10) + 1;
else ans = (X / 10);
}
else if (X < 0) ans = (X / 10);
else ans = 0;
std::cout << ans << std::endl;
}
C問題 One Time Swap
#include <iostream>
#include <vector>
#include <map>
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; }
else return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; }
return false;
}
int main() {
std::string S;
std::cin >> S;
//std::map<std::string, bool> mp;
std::vector<long long> Used(26, 0);
for (long long i = 0; i < S.size(); i++) Used[S[i] - 'a']++;
long long ans = 0;
for (int c = 0; c < (Used.size() - 1); c++) {
for (int cc = (c+1); cc < Used.size(); cc++) {
ans += Used[c] * Used[cc];
}
}
bool same = false;
for (int c = 0; c < Used.size(); c++) if (1 < Used[c]) same = true;
if (same == true) ans++;
std::cout << ans << std::endl;
}
26種類しかないアルファベット(英小文字)に着目すると解ける問題。
入れ替えた後に入力文字列と同じ文字列ができるかどうかの判定が肝かな。
D問題 Tiling



コメント