problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02691
C++
Runtime Error
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FRE freopen("in.txt", "r", stdin); #define endl "\n" #define PI acos(-1.0) typedef long long LL; typedef pair<int, int> PII; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int N = 1e5 + 10, M = 1010; LL a[N]; map<LL, LL> cnt; void solve() { int n; cin >> n; LL res = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; res += cnt[i - a[i]]; cnt[a[i] + i]++; } cout << res << endl; } int main() { IOS; int t; solve(); return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FRE freopen("in.txt", "r", stdin); #define endl "\n" #define PI acos(-1.0) typedef long long LL; typedef pair<int, int> PII; const double eps = 1e-8; const int inf = 0x3f3f3f3f; const int N = 2e5 + 10, M = 1010; LL a[N]; map<LL, LL> cnt; void solve() { int n; cin >> n; LL res = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; res += cnt[i - a[i]]; cnt[a[i] + i]++; } cout << res << endl; } int main() { IOS; int t; solve(); return 0; }
replace
14
15
14
15
0
p02691
C++
Runtime Error
/** * ///----- My Info -----/// * Code by: Ernesto Abreu * Codeforces User: Ernest0_0Abreu * Country: Cuba * E-mail: ernestoabreup@gmail.com * CopyRight **/ #include <bits/stdc++.h> #ifdef Ernest0_0Abreu #include <debug/to_string.h> #endif using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") ///----- My Template -----/// ///====================================================================================================================================== /// Red-Black Tree // #include <ext/pb_ds/assoc_container.hpp> // .find_of_order(x); // .order_of_key(x); using namespace __gnu_pbds; typedef tree< int, null_type, // less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set; /// Function #define pi (acos(-1)) #define lg2(x) 31 - __builtin_clz(x) #define lgx(x, b) log(b) / log(x) /// Macros #define fst first #define scd second #define left (node << 1) #define right ((node << 1) + 1) #define size(x) (int)(x.size()) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() /// Debug #define _end cout << "\n" #ifdef Ernest0_0Abreu #define db(x) cerr << "[ " << #x << " ]: " << to_string(x) << "\n" #define dbrange(x, begin, end) \ cerr << "[ " << #x << " ]: " << to_string(x, begin, end) << "\n" #define dbname(x) cerr << to_string(x, #x) << "\n" #define dbnamerange(x, begin, end) cerr << to_string(x, #x, begin, end) << "\n" #define dbmat(x, begin_n, end_n, begin_m, end_m) \ cerr << to_string(x, #x, begin_n, end_n, begin_m, end_m) << "\n" #define dbST(x, end) cerr << to_string(x, end) << "\n"; #define dbendl cerr << "\n"; #else #define db(x) ; #define dbrange(x, begin, end) ; #define dbname(x) ; #define dbnamerange(x, begin, end) ; #define dbmat(x, begin_n, end_n, begin_m, end_m) ; #define dbST(x, end) ; #define dbendl ; #endif /// Typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; /// Constant const int MAXN = 2e5 + 7; const int MOD = 1e9; const ull BASE = 311; const ld EPS = 1e-9; const int INF = ((1 << 30) - 1); const ll INFLL = ((1ll << 62ll) - 1ll); const ll oo = 2e18; /// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027; /// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, /// 1000000033; ///======================================================================================================================================= #define int long long ///----- My code -----/// int ar[MAXN], cnt[MAXN]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; int ans = 0; for (int i = 1; i <= N; ++i) { cin >> ar[i]; if (i + ar[i] < MAXN) cnt[i + ar[i] - 1]++; if (i - ar[i] - 1 >= 1) continue; ans += cnt[i - ar[i] - 1]; } cout << ans; return 0; }
/** * ///----- My Info -----/// * Code by: Ernesto Abreu * Codeforces User: Ernest0_0Abreu * Country: Cuba * E-mail: ernestoabreup@gmail.com * CopyRight **/ #include <bits/stdc++.h> #ifdef Ernest0_0Abreu #include <debug/to_string.h> #endif using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") ///----- My Template -----/// ///====================================================================================================================================== /// Red-Black Tree // #include <ext/pb_ds/assoc_container.hpp> // .find_of_order(x); // .order_of_key(x); using namespace __gnu_pbds; typedef tree< int, null_type, // less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set; /// Function #define pi (acos(-1)) #define lg2(x) 31 - __builtin_clz(x) #define lgx(x, b) log(b) / log(x) /// Macros #define fst first #define scd second #define left (node << 1) #define right ((node << 1) + 1) #define size(x) (int)(x.size()) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() /// Debug #define _end cout << "\n" #ifdef Ernest0_0Abreu #define db(x) cerr << "[ " << #x << " ]: " << to_string(x) << "\n" #define dbrange(x, begin, end) \ cerr << "[ " << #x << " ]: " << to_string(x, begin, end) << "\n" #define dbname(x) cerr << to_string(x, #x) << "\n" #define dbnamerange(x, begin, end) cerr << to_string(x, #x, begin, end) << "\n" #define dbmat(x, begin_n, end_n, begin_m, end_m) \ cerr << to_string(x, #x, begin_n, end_n, begin_m, end_m) << "\n" #define dbST(x, end) cerr << to_string(x, end) << "\n"; #define dbendl cerr << "\n"; #else #define db(x) ; #define dbrange(x, begin, end) ; #define dbname(x) ; #define dbnamerange(x, begin, end) ; #define dbmat(x, begin_n, end_n, begin_m, end_m) ; #define dbST(x, end) ; #define dbendl ; #endif /// Typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; /// Constant const int MAXN = 2e5 + 7; const int MOD = 1e9; const ull BASE = 311; const ld EPS = 1e-9; const int INF = ((1 << 30) - 1); const ll INFLL = ((1ll << 62ll) - 1ll); const ll oo = 2e18; /// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027; /// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, /// 1000000033; ///======================================================================================================================================= #define int long long ///----- My code -----/// int ar[MAXN], cnt[MAXN]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; int ans = 0; for (int i = 1; i <= N; ++i) { cin >> ar[i]; if (i + ar[i] < MAXN) cnt[i + ar[i] - 1]++; if (i - ar[i] - 1 < 1) continue; ans += cnt[i - ar[i] - 1]; } cout << ans; return 0; }
replace
90
91
90
91
0
p02691
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(p, a, b) for (int p = a; p < b; p++) #define INF 0x3f3f3f3f #define N 100007 int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("o2.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, i, ans = 0; map<ll, ll> m; cin >> n; vector<ll> h(n); for (i = 1; i <= n; i++) { cin >> h[i]; m[i + h[i]]++; } for (i = 1; i <= n; i++) ans += m[i - h[i]]; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(p, a, b) for (int p = a; p < b; p++) #define INF 0x3f3f3f3f #define N 100007 int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("o2.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, i, ans = 0; map<ll, ll> m; cin >> n; vector<ll> h(n + 1); for (i = 1; i <= n; i++) { cin >> h[i]; m[i + h[i]]++; } for (i = 1; i <= n; i++) ans += m[i - h[i]]; cout << ans; return 0; }
replace
23
24
23
24
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02691
C++
Runtime Error
#include <cstdio> #include <iostream> #include <map> using namespace std; #define ll long long const int MAX = 1e5 + 111; int n; ll h[MAX]; ll ans = 0; map<ll, ll> p; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> h[i]; ll m = i - h[i]; if (p.count(m) != 0) ans += p[m]; p[i + h[i]]++; } printf("%lld\n", ans); }
#include <cstdio> #include <iostream> #include <map> using namespace std; #define ll long long const int MAX = 2e5 + 111; int n; ll h[MAX]; ll ans = 0; map<ll, ll> p; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { cin >> h[i]; ll m = i - h[i]; if (p.count(m) != 0) ans += p[m]; p[i + h[i]]++; } printf("%lld\n", ans); }
replace
6
7
6
7
0
p02691
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define repl(i, l, r) for (long long i = (l); i < (r); i++) #define rep(i, n) for (long long i = 0; i < (n); ++i) #define per(i, n) for (long long i = (n); i >= 0; --i) const int INF = 2147483647; // int max const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // ミョ(-ω- ?) int main() { ll n; cin >> n; vector<ll> h(n); rep(i, n) cin >> h[i]; ll ans = 0; rep(i, n) { repl(j, i + 1, n) { if (abs(i - j) == h[i] + h[j]) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define repl(i, l, r) for (long long i = (l); i < (r); i++) #define rep(i, n) for (long long i = 0; i < (n); ++i) #define per(i, n) for (long long i = (n); i >= 0; --i) const int INF = 2147483647; // int max const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // ミョ(-ω- ?) int main() { ll n; cin >> n; vector<ll> a(n, 0); rep(i, n) cin >> a[i]; unordered_map<ll, ll> um; rep(i, n) um[i + a[i]]++; ll res = 0; rep(i, n) res += um[i - a[i]]; cout << res << endl; return 0; }
replace
27
37
27
34
TLE
p02691
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; int main(int argc, char *argv[]) { long long N; cin >> N; vector<long long> a(N); vector<long long> score(N); for (int i = 0; i < N; ++i) { long long tmp; cin >> tmp; a[i] = tmp; score[i] = i - tmp; } vector<long long> s = score; sort(s.begin(), s.end()); long long ret = 0; for (int i = 0; i < N; ++i) { long long cur = i + a[i]; vector<long long>::iterator j = lower_bound(s.begin(), s.end(), i + a[i]); while (true) { if (j == s.end() || *j > cur) break; if (cur == *j) ++ret; ++j; } } cout << ret << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; int main(int argc, char *argv[]) { long long N; cin >> N; vector<long long> a(N); vector<long long> score(N); for (int i = 0; i < N; ++i) { long long tmp; cin >> tmp; a[i] = tmp; score[i] = i - tmp; } vector<long long> s = score; sort(s.begin(), s.end()); long long ret = 0; for (int i = 0; i < N; ++i) { long long cur = i + a[i]; vector<long long>::iterator j = lower_bound(s.begin(), s.end(), i + a[i]); vector<long long>::iterator k = upper_bound(s.begin(), s.end(), i + a[i]); if (j == s.end() || *j > cur) continue; if (k == s.end()) ret += distance(j, s.end()); else ret += distance(j, k); } cout << ret << endl; return 0; }
replace
27
34
27
34
TLE
p02691
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #ifndef LX_DEBUG // #define LX_DEBUG #endif #if defined(__unix__) && !defined(LX_DEBUG) && !defined(LX_LOCAL) #define USE_MMAP 1 #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #else #define USE_MMAP 0 #endif using LL = long long; using ULL = unsigned long long; #ifdef __SIZEOF_INT128__ using LLL = __int128; using ULLL = unsigned __int128; #else using LLL = long long; using ULLL = unsigned long long; #endif namespace std { #define def(type) \ void swap(type &x, type &y) { x ^= y ^= x ^= y; } def(char); def(signed char); def(unsigned char); def(short); def(unsigned short); def(int); def(unsigned int); def(LL); def(ULL); #ifdef __SIZEOF_INT128__ def(LLL); def(ULLL); #endif #undef def }; // namespace std #ifdef LX_LOCAL #include <ctime> class Time { public: clock_t begin; Time() { begin = clock(); } ~Time() { double t = (clock() - begin) * 1000.0 / static_cast<double>(CLOCKS_PER_SEC); fprintf(stderr, "Time used = "); if (t >= 60000) fprintf(stderr, "%.2lfmin\n", t / 60000.0); else if (t >= 1000) fprintf(stderr, "%.2lfs\n", t / 1000.0); else fprintf(stderr, "%.0lfms\n", t); } } timeout; #endif using std::swap; #if __cplusplus >= 201402L template <typename T, typename P> inline constexpr auto max(const T &x, const P &y) { return x < y ? y : x; } template <typename T, typename P> inline constexpr auto min(const T &x, const P &y) { return x < y ? x : y; } template <typename T, typename... Args> inline constexpr auto max(const T &x, const Args &...args) { return max(x, max(args...)); } template <typename T, typename... Args> inline constexpr auto min(const T &x, const Args &...args) { return min(x, min(args...)); } #else template <typename T, typename P> inline constexpr auto max(const T &x, const P &y) -> decltype(x < y ? y : x) { return x < y ? y : x; } template <typename T, typename P> inline constexpr auto min(const T &x, const P &y) -> decltype(x < y ? x : y) { return x < y ? x : y; } template <typename T, typename... Args> inline constexpr auto max(const T &x, const Args &...args) -> decltype(max(x, max(args...))) { return max(x, max(args...)); } template <typename T, typename... Args> inline constexpr auto min(const T &x, const Args &...args) -> decltype(min(x, min(args...))) { return min(x, min(args...)); } #endif template <typename T> inline constexpr T max(const T &x) { return x; } template <typename T> inline constexpr T min(const T &x) { return x; } template <typename T, typename... Args> inline void chkmax(T &d, const Args &...args) { d = max(d, args...); } template <typename T, typename... Args> inline void chkmin(T &d, const Args &...args) { d = min(d, args...); } #define lc (o << 1) #define rc (o << 1 | 1) #define lowbit(x) ((x) & (-(x))) #define all(x) x.begin(), x.end() #define SZ(x) int(x.size()) #pragma region IO constexpr size_t bufSize = 1 << 20; class In { private: FILE *inFile = nullptr; #if USE_MMAP struct stat st; char *ptr; int fd; size_t pos; #elif !defined(LX_DEBUG) char buf[bufSize], *p1, *p2; #endif public: #ifdef LX_DEBUG inline int getch() { return fgetc(inFile); } inline void putback(char c) { ungetc(c, inFile); } inline void input(FILE *f) { inFile = f; } inline void input(const char *str) { inFile = fopen(str, "rb"); } #elif USE_MMAP inline int getch() { return *(ptr + pos) ? *(ptr + (pos++)) : EOF; } inline void putback(char c) { pos--; } inline void input(FILE *f) { if ((inFile = f)) fd = fileno(inFile), fstat(fd, &st), ptr = (char *)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), pos = 0; } inline void input(const char *str) { fd = open(str, O_RDONLY), fstat(fd, &st), ptr = (char *)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), pos = 0; } #else inline int getch() { return (p1 == p2 ? (p2 = (p1 = buf) + fread(buf, 1, bufSize, inFile)) : 0), (p1 == p2) ? EOF : *p1++; } inline void putback(char c) { *(--p1) = c; } inline void input(FILE *f) { inFile = f, p1 = p2 = buf; } inline void input(const char *str) { inFile = fopen(str, "rb"), p1 = p2 = buf; } #endif }; class Out { private: FILE *outFile = nullptr; #ifndef LX_DEBUG char pbuf[bufSize], *pp; #endif public: #ifdef LX_DEBUG inline void flush() { outFile ? fflush(outFile) : 0; } inline void putch(const char c) { fputc(c, outFile); } #else inline void flush() { (outFile ? fwrite(pbuf, 1, pp - pbuf, outFile), fflush(outFile) : 0), pp = pbuf; } inline void putch(const char c) { ((pp - pbuf == bufSize) ? fwrite(pbuf, 1, bufSize, outFile), pp = pbuf : 0), *pp++ = c; } #endif inline void output(const char *str) { flush(), outFile = fopen(str, "wb"); } inline void output(FILE *f) { flush(), outFile = f; } }; class IO : public In, public Out { private: long double eps = 1e-8L; LLL pow10 = 1000000; size_t precision = 6; public: IO(FILE *in = nullptr, FILE *out = nullptr); ~IO(); inline void flush(); inline static constexpr bool blank(char ch); template <typename T, typename... Args> bool read(T &x, Args &...args); template <typename T> typename std::enable_if< (std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, LLL>::value, bool>::type read(T &x); template <typename T> typename std::enable_if< (std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, ULLL>::value, bool>::type read(T &x); template <typename T> typename std::enable_if<std::is_floating_point<T>::value, bool>::type read(T &x); template <typename T> typename std::enable_if< std::is_integral<T>::value || std::is_floating_point<T>::value || std::is_same<typename std::remove_cv<T>::type, LLL>::value || std::is_same<typename std::remove_cv<T>, ULLL>::value, T>::type read(); bool read(char &ch); bool read(char *s); bool readline(char *s); inline void setprecision(size_t n = 6u); template <typename T, typename... Args> void write(const T &x, const Args &...args); inline void write() const {} template <typename T> typename std::enable_if<(std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<T, LLL>::value, void>::type write(T x); template <typename T> typename std::enable_if<(std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<T, ULLL>::value, void>::type write(T x); inline void write(char c); template <typename T> typename std::enable_if<std::is_floating_point<T>::value, void>::type write(T x); inline void write(bool x); void write(char *s); void write(const char *s); template <typename... Args> void writeln(Args... x); } io(stdin, stdout), err(nullptr, stderr); template <typename... Args> inline void writeln(Args... x) { io.write(x...), io.putch('\n'); } #define dbg(x) err.write(#x " = "), err.writeln(x) #pragma endregion IO #include <map> const int maxn = 100005; int A[maxn]; int main() { int n; io.read(n); for (int i = 1; i <= n; i++) io.read(A[i]); std::map<int, int> mp, mp2; for (int i = 1; i <= n; i++) mp[i - A[i]]++; LL ans = 0; for (int i = 1; i <= n; i++) ans += mp[A[i] + i]; writeln(ans); return 0; } #define isdigit(x) (x >= '0' && x <= '9') IO::IO(FILE *in, FILE *out) { input(in), output(out); } IO::~IO() { flush(); } inline void IO::flush() { Out::flush(); } inline constexpr bool IO::blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } template <typename T, typename... Args> bool IO::read(T &x, Args &...args) { return read(x) && (sizeof...(args) ? read(args...) : true); } template <typename T> typename std::enable_if< (std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, LLL>::value, bool>::type IO::read(T &x) { x = 0; bool sign = false; int ch = getch(); while (!isdigit(ch) && ~ch) sign &= (ch == '-'), ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getch(); if (~ch) putback(ch); x = sign ? (~x + 1) : x; return true; } template <typename T> typename std::enable_if< (std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, ULLL>::value, bool>::type IO::read(T &x) { x = 0; int ch = getch(); while (!isdigit(ch) && ~ch) ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getch(); if (~ch) putback(ch); return true; } template <typename T> typename std::enable_if<std::is_floating_point<T>::value, bool>::type IO::read(T &x) { x = 0; T tmp = 1; bool sign = false; int ch = getch(); while (!isdigit(ch) && ~ch) sign &= (ch == '-'), ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getch(); if (ch == '.') for (ch = getch(); isdigit(ch); ch = getch()) x += (tmp /= 10.0) * (ch ^ '0'); if (~ch) putback(ch); x = sign ? (-x) : x; return true; } template <typename T> typename std::enable_if< std::is_integral<T>::value || std::is_floating_point<T>::value || std::is_same<typename std::remove_cv<T>::type, LLL>::value || std::is_same<typename std::remove_cv<T>, ULLL>::value, T>::type IO::read() { typename std::remove_cv<T>::type x; read(x); return x; } bool IO::read(char &ch) { do ch = getch(); while (blank(ch) && ~ch); return ~ch; } bool IO::read(char *s) { int ch = getch(); while (blank(ch)) ch = getch(); if (!(~ch)) return false; while (!blank(ch) && ~ch) *s++ = ch, ch = getch(); *s = 0; if (~ch) putback(ch); return true; } bool IO::readline(char *s) { int ch = getch(); while (blank(ch) && (ch ^ '\n')) ch = getch(); if (!(~ch)) return false; while ((ch ^ '\n') && ~ch) *s++ = ch, ch = getch(); *s = 0; if (~ch) putback(ch); return true; } inline void IO::setprecision(size_t n) { precision = n; eps = powl(10.0L, -precision - 2); pow10 = powl(10.0L, precision) + eps; } template <typename T, typename... Args> void IO::write(const T &x, const Args &...args) { write(x); if (sizeof...(args)) write(args...); } template <typename T> typename std::enable_if<(std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<T, LLL>::value, void>::type IO::write(T x) { if (x < 0) x = ~x + 1, putch('-'); static int sta[40], top = 0; do sta[top++] = x % 10, x /= 10; while (x); while (top) putch(sta[--top] ^ '0'); } template <typename T> typename std::enable_if<(std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<T, ULLL>::value, void>::type IO::write(T x) { static int sta[40], top = 0; do sta[top++] = x % 10, x /= 10; while (x); while (top) putch(sta[--top] ^ '0'); } inline void IO::write(bool x) { putch(x ^ 48); } inline void IO::write(char c) { putch(c); } template <typename T> typename std::enable_if<std::is_floating_point<T>::value>::type IO::write(T x) { if (x == 0) { putch('0'), putch('.'); for (int i = 1; i <= precision; i++) putch('0'); return; } if (x < 0) putch('-'), x = -x; T res = (LLL)(x * pow10 + 0.5) / (pow10 * 1.0); LLL y = LLL(res * pow10 + eps) % pow10; write(LLL(res + eps)); if (precision) { putch('.'); static int sta[100], p = 0; while (p < precision) sta[++p] = y % 10, y /= 10; for (int i = p; i >= 1; i--) putch(sta[i] ^ 48); } } void IO::write(char *s) { while (*s) putch(*s++); } void IO::write(const char *s) { while (*s) putch(*s++); } template <typename... Args> void IO::writeln(Args... x) { write(x...), putch('\n'); } #undef isdigit
#include <algorithm> #include <cmath> #include <cstdio> #ifndef LX_DEBUG // #define LX_DEBUG #endif #if defined(__unix__) && !defined(LX_DEBUG) && !defined(LX_LOCAL) #define USE_MMAP 1 #include <fcntl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #else #define USE_MMAP 0 #endif using LL = long long; using ULL = unsigned long long; #ifdef __SIZEOF_INT128__ using LLL = __int128; using ULLL = unsigned __int128; #else using LLL = long long; using ULLL = unsigned long long; #endif namespace std { #define def(type) \ void swap(type &x, type &y) { x ^= y ^= x ^= y; } def(char); def(signed char); def(unsigned char); def(short); def(unsigned short); def(int); def(unsigned int); def(LL); def(ULL); #ifdef __SIZEOF_INT128__ def(LLL); def(ULLL); #endif #undef def }; // namespace std #ifdef LX_LOCAL #include <ctime> class Time { public: clock_t begin; Time() { begin = clock(); } ~Time() { double t = (clock() - begin) * 1000.0 / static_cast<double>(CLOCKS_PER_SEC); fprintf(stderr, "Time used = "); if (t >= 60000) fprintf(stderr, "%.2lfmin\n", t / 60000.0); else if (t >= 1000) fprintf(stderr, "%.2lfs\n", t / 1000.0); else fprintf(stderr, "%.0lfms\n", t); } } timeout; #endif using std::swap; #if __cplusplus >= 201402L template <typename T, typename P> inline constexpr auto max(const T &x, const P &y) { return x < y ? y : x; } template <typename T, typename P> inline constexpr auto min(const T &x, const P &y) { return x < y ? x : y; } template <typename T, typename... Args> inline constexpr auto max(const T &x, const Args &...args) { return max(x, max(args...)); } template <typename T, typename... Args> inline constexpr auto min(const T &x, const Args &...args) { return min(x, min(args...)); } #else template <typename T, typename P> inline constexpr auto max(const T &x, const P &y) -> decltype(x < y ? y : x) { return x < y ? y : x; } template <typename T, typename P> inline constexpr auto min(const T &x, const P &y) -> decltype(x < y ? x : y) { return x < y ? x : y; } template <typename T, typename... Args> inline constexpr auto max(const T &x, const Args &...args) -> decltype(max(x, max(args...))) { return max(x, max(args...)); } template <typename T, typename... Args> inline constexpr auto min(const T &x, const Args &...args) -> decltype(min(x, min(args...))) { return min(x, min(args...)); } #endif template <typename T> inline constexpr T max(const T &x) { return x; } template <typename T> inline constexpr T min(const T &x) { return x; } template <typename T, typename... Args> inline void chkmax(T &d, const Args &...args) { d = max(d, args...); } template <typename T, typename... Args> inline void chkmin(T &d, const Args &...args) { d = min(d, args...); } #define lc (o << 1) #define rc (o << 1 | 1) #define lowbit(x) ((x) & (-(x))) #define all(x) x.begin(), x.end() #define SZ(x) int(x.size()) #pragma region IO constexpr size_t bufSize = 1 << 20; class In { private: FILE *inFile = nullptr; #if USE_MMAP struct stat st; char *ptr; int fd; size_t pos; #elif !defined(LX_DEBUG) char buf[bufSize], *p1, *p2; #endif public: #ifdef LX_DEBUG inline int getch() { return fgetc(inFile); } inline void putback(char c) { ungetc(c, inFile); } inline void input(FILE *f) { inFile = f; } inline void input(const char *str) { inFile = fopen(str, "rb"); } #elif USE_MMAP inline int getch() { return *(ptr + pos) ? *(ptr + (pos++)) : EOF; } inline void putback(char c) { pos--; } inline void input(FILE *f) { if ((inFile = f)) fd = fileno(inFile), fstat(fd, &st), ptr = (char *)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), pos = 0; } inline void input(const char *str) { fd = open(str, O_RDONLY), fstat(fd, &st), ptr = (char *)mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), pos = 0; } #else inline int getch() { return (p1 == p2 ? (p2 = (p1 = buf) + fread(buf, 1, bufSize, inFile)) : 0), (p1 == p2) ? EOF : *p1++; } inline void putback(char c) { *(--p1) = c; } inline void input(FILE *f) { inFile = f, p1 = p2 = buf; } inline void input(const char *str) { inFile = fopen(str, "rb"), p1 = p2 = buf; } #endif }; class Out { private: FILE *outFile = nullptr; #ifndef LX_DEBUG char pbuf[bufSize], *pp; #endif public: #ifdef LX_DEBUG inline void flush() { outFile ? fflush(outFile) : 0; } inline void putch(const char c) { fputc(c, outFile); } #else inline void flush() { (outFile ? fwrite(pbuf, 1, pp - pbuf, outFile), fflush(outFile) : 0), pp = pbuf; } inline void putch(const char c) { ((pp - pbuf == bufSize) ? fwrite(pbuf, 1, bufSize, outFile), pp = pbuf : 0), *pp++ = c; } #endif inline void output(const char *str) { flush(), outFile = fopen(str, "wb"); } inline void output(FILE *f) { flush(), outFile = f; } }; class IO : public In, public Out { private: long double eps = 1e-8L; LLL pow10 = 1000000; size_t precision = 6; public: IO(FILE *in = nullptr, FILE *out = nullptr); ~IO(); inline void flush(); inline static constexpr bool blank(char ch); template <typename T, typename... Args> bool read(T &x, Args &...args); template <typename T> typename std::enable_if< (std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, LLL>::value, bool>::type read(T &x); template <typename T> typename std::enable_if< (std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, ULLL>::value, bool>::type read(T &x); template <typename T> typename std::enable_if<std::is_floating_point<T>::value, bool>::type read(T &x); template <typename T> typename std::enable_if< std::is_integral<T>::value || std::is_floating_point<T>::value || std::is_same<typename std::remove_cv<T>::type, LLL>::value || std::is_same<typename std::remove_cv<T>, ULLL>::value, T>::type read(); bool read(char &ch); bool read(char *s); bool readline(char *s); inline void setprecision(size_t n = 6u); template <typename T, typename... Args> void write(const T &x, const Args &...args); inline void write() const {} template <typename T> typename std::enable_if<(std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<T, LLL>::value, void>::type write(T x); template <typename T> typename std::enable_if<(std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<T, ULLL>::value, void>::type write(T x); inline void write(char c); template <typename T> typename std::enable_if<std::is_floating_point<T>::value, void>::type write(T x); inline void write(bool x); void write(char *s); void write(const char *s); template <typename... Args> void writeln(Args... x); } io(stdin, stdout), err(nullptr, stderr); template <typename... Args> inline void writeln(Args... x) { io.write(x...), io.putch('\n'); } #define dbg(x) err.write(#x " = "), err.writeln(x) #pragma endregion IO #include <map> const int maxn = 200005; int A[maxn]; int main() { int n; io.read(n); for (int i = 1; i <= n; i++) io.read(A[i]); std::map<int, int> mp, mp2; for (int i = 1; i <= n; i++) mp[i - A[i]]++; LL ans = 0; for (int i = 1; i <= n; i++) ans += mp[A[i] + i]; writeln(ans); return 0; } #define isdigit(x) (x >= '0' && x <= '9') IO::IO(FILE *in, FILE *out) { input(in), output(out); } IO::~IO() { flush(); } inline void IO::flush() { Out::flush(); } inline constexpr bool IO::blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } template <typename T, typename... Args> bool IO::read(T &x, Args &...args) { return read(x) && (sizeof...(args) ? read(args...) : true); } template <typename T> typename std::enable_if< (std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, LLL>::value, bool>::type IO::read(T &x) { x = 0; bool sign = false; int ch = getch(); while (!isdigit(ch) && ~ch) sign &= (ch == '-'), ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getch(); if (~ch) putback(ch); x = sign ? (~x + 1) : x; return true; } template <typename T> typename std::enable_if< (std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<typename std::remove_cv<T>::type, ULLL>::value, bool>::type IO::read(T &x) { x = 0; int ch = getch(); while (!isdigit(ch) && ~ch) ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getch(); if (~ch) putback(ch); return true; } template <typename T> typename std::enable_if<std::is_floating_point<T>::value, bool>::type IO::read(T &x) { x = 0; T tmp = 1; bool sign = false; int ch = getch(); while (!isdigit(ch) && ~ch) sign &= (ch == '-'), ch = getch(); if (!(~ch)) return false; while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getch(); if (ch == '.') for (ch = getch(); isdigit(ch); ch = getch()) x += (tmp /= 10.0) * (ch ^ '0'); if (~ch) putback(ch); x = sign ? (-x) : x; return true; } template <typename T> typename std::enable_if< std::is_integral<T>::value || std::is_floating_point<T>::value || std::is_same<typename std::remove_cv<T>::type, LLL>::value || std::is_same<typename std::remove_cv<T>, ULLL>::value, T>::type IO::read() { typename std::remove_cv<T>::type x; read(x); return x; } bool IO::read(char &ch) { do ch = getch(); while (blank(ch) && ~ch); return ~ch; } bool IO::read(char *s) { int ch = getch(); while (blank(ch)) ch = getch(); if (!(~ch)) return false; while (!blank(ch) && ~ch) *s++ = ch, ch = getch(); *s = 0; if (~ch) putback(ch); return true; } bool IO::readline(char *s) { int ch = getch(); while (blank(ch) && (ch ^ '\n')) ch = getch(); if (!(~ch)) return false; while ((ch ^ '\n') && ~ch) *s++ = ch, ch = getch(); *s = 0; if (~ch) putback(ch); return true; } inline void IO::setprecision(size_t n) { precision = n; eps = powl(10.0L, -precision - 2); pow10 = powl(10.0L, precision) + eps; } template <typename T, typename... Args> void IO::write(const T &x, const Args &...args) { write(x); if (sizeof...(args)) write(args...); } template <typename T> typename std::enable_if<(std::is_signed<T>::value && std::is_integral<T>::value) || std::is_same<T, LLL>::value, void>::type IO::write(T x) { if (x < 0) x = ~x + 1, putch('-'); static int sta[40], top = 0; do sta[top++] = x % 10, x /= 10; while (x); while (top) putch(sta[--top] ^ '0'); } template <typename T> typename std::enable_if<(std::is_unsigned<T>::value && std::is_integral<T>::value) || std::is_same<T, ULLL>::value, void>::type IO::write(T x) { static int sta[40], top = 0; do sta[top++] = x % 10, x /= 10; while (x); while (top) putch(sta[--top] ^ '0'); } inline void IO::write(bool x) { putch(x ^ 48); } inline void IO::write(char c) { putch(c); } template <typename T> typename std::enable_if<std::is_floating_point<T>::value>::type IO::write(T x) { if (x == 0) { putch('0'), putch('.'); for (int i = 1; i <= precision; i++) putch('0'); return; } if (x < 0) putch('-'), x = -x; T res = (LLL)(x * pow10 + 0.5) / (pow10 * 1.0); LLL y = LLL(res * pow10 + eps) % pow10; write(LLL(res + eps)); if (precision) { putch('.'); static int sta[100], p = 0; while (p < precision) sta[++p] = y % 10, y /= 10; for (int i = p; i >= 1; i--) putch(sta[i] ^ 48); } } void IO::write(char *s) { while (*s) putch(*s++); } void IO::write(const char *s) { while (*s) putch(*s++); } template <typename... Args> void IO::writeln(Args... x) { write(x...), putch('\n'); } #undef isdigit
replace
257
258
257
258
-11
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> v; vector<char> ans; bool ok = 1; ll n, t; ll ind = 0; void solve(string s) { if (!v[s[0] - 'A'] && !v[s[1] - 'A']) { ok = 0; return; } if (!v[s[0] - 'A']) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else if (!v[s[1] - 'A']) v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; else { if (t == 2) { if (n--) { string c; cin >> c; if (s[0] == c[0] || s[0] == c[1]) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; solve(c); } else v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; } else { if (v[s[1] - 'A'] == t - 1) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; } } } int main() { cin >> n; v.resize(3), ans.resize(n); cin >> v[0] >> v[1] >> v[2]; t = v[0] + v[1] + v[2]; while (n--) { string s; cin >> s; if (!ok) continue; solve(s); } if (n == 0 || !ok) cout << "No"; else { cout << "Yes\n"; for (char c : ans) cout << c << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> v; vector<char> ans; bool ok = 1; ll n, t; ll ind = 0; void solve(string s) { if (!v[s[0] - 'A'] && !v[s[1] - 'A']) { ok = 0; return; } if (!v[s[0] - 'A']) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else if (!v[s[1] - 'A']) v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; else { if (t == 2) { if (n--) { string c; cin >> c; if (s[0] == c[0] || s[0] == c[1]) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; solve(c); } else v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; } else { if (v[s[1] - 'A'] == t - 1) v[s[0] - 'A']++, v[s[1] - 'A']--, ans[ind++] = s[0]; else v[s[1] - 'A']++, v[s[0] - 'A']--, ans[ind++] = s[1]; } } } int main() { cin >> n; v.resize(3), ans.resize(n); cin >> v[0] >> v[1] >> v[2]; t = v[0] + v[1] + v[2]; while (n-- > 0) { string s; cin >> s; if (!ok) continue; solve(s); } if (n == 0 || !ok) cout << "No"; else { cout << "Yes\n"; for (char c : ans) cout << c << "\n"; } return 0; }
replace
45
46
45
46
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } #define all(x) (x).begin(), (x).end() #define rep(i, N) for (int i = 0; i < (int)(N); i++) void solve() { int N; vector<int> D(3); cin >> N >> D; vector<string> s(N); cin >> s; vector<char> ans; rep(i, N) { int first = s[i][0] - 'A'; int second = s[i][1] - 'A'; if (D[first] == 0 and D[second] == 0) { cout << "No" << endl; return; } int greater; int less; if (D[first] == 1 and D[second] == 1 and i + 1 < N) { int rest = 0 + 1 + 2 - first - second; if (count(all(s[i + 1]), (char)('A' + rest)) == 1) { if (count(all(s[i + 1]), (char)('A' + first)) == 1) { greater = second; less = first; } else { greater = first; less = second; } } } else if (D[first] >= D[second]) { greater = first; less = second; } else { greater = second; less = first; } D[greater]--; D[less]++; ans.push_back('A' + less); } cout << "Yes" << endl; rep(i, N) cout << ans[i] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } #define all(x) (x).begin(), (x).end() #define rep(i, N) for (int i = 0; i < (int)(N); i++) void solve() { int N; vector<int> D(3); cin >> N >> D; vector<string> s(N); cin >> s; vector<char> ans; rep(i, N) { int first = s[i][0] - 'A'; int second = s[i][1] - 'A'; if (D[first] == 0 and D[second] == 0) { cout << "No" << endl; return; } int greater; int less; int rest = 0 + 1 + 2 - first - second; if (D[first] == 1 and D[second] == 1 and i + 1 < N and count(all(s[i + 1]), (char)('A' + rest)) == 1) { if (count(all(s[i + 1]), (char)('A' + first)) == 1) { greater = second; less = first; } else { greater = first; less = second; } } else if (D[first] >= D[second]) { greater = first; less = second; } else { greater = second; less = first; } D[greater]--; D[less]++; ans.push_back('A' + less); } cout << "Yes" << endl; rep(i, N) cout << ans[i] << endl; } int main() { solve(); return 0; }
replace
30
40
30
39
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, b, e) for (int i = (b); i < (e); ++i) #define RREP(i, b, e) for (int i = (b)-1; i >= e; --i) #define rep(i, e) for (int i = 0; i < (e); ++i) struct Initializer { Initializer() { cin.tie(0); ios::sync_with_stdio(0); } } initializer; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto it = vec.begin(); it != vec.end(); ++it) { if (it != vec.begin()) os << ", "; os << *it; } return os << "]"; } inline void print(void) { cout << '\n'; } template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T, class... U> inline void print(const T &x, const U &...y) { cout << x << " "; print(y...); } long long n, a, b, c; vector<string> s = {}, ans = {}; bool good = false; void rec(int idx, vector<string> &v, long long a, long long b, long long c) { if (good) return; if (idx == n) { if (a >= 0 and b >= 0 and c >= 0) { copy(v.begin(), v.end(), ans.begin()); good = true; } else { return; } } if (a < 0 or b < 0 or c < 0) return; if (s[idx] == "AB") { v.emplace_back("A"); rec(idx + 1, v, a + 1, b - 1, c); if (good) return; v.pop_back(); v.emplace_back("B"); rec(idx + 1, v, a - 1, b + 1, c); if (good) return; v.pop_back(); } else if (s[idx] == "AC") { v.emplace_back("A"); rec(idx + 1, v, a + 1, b, c - 1); if (good) return; v.pop_back(); v.emplace_back("C"); rec(idx + 1, v, a - 1, b, c + 1); if (good) return; v.pop_back(); } else { v.emplace_back("B"); rec(idx + 1, v, a, b + 1, c - 1); if (good) return; v.pop_back(); v.emplace_back("C"); rec(idx + 1, v, a, b - 1, c + 1); if (good) return; v.pop_back(); } } int main() { cin >> n >> a >> b >> c; rep(i, n) { string st; cin >> st; s.emplace_back(st); } ans.resize(n); vector<string> v = {}; rec(0, v, a, b, c); if (good) { print("Yes"); for (auto x : ans) print(x); } else { print("No"); } return 0; }
#include <iostream> #include <vector> using namespace std; #define REP(i, b, e) for (int i = (b); i < (e); ++i) #define RREP(i, b, e) for (int i = (b)-1; i >= e; --i) #define rep(i, e) for (int i = 0; i < (e); ++i) struct Initializer { Initializer() { cin.tie(0); ios::sync_with_stdio(0); } } initializer; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto it = vec.begin(); it != vec.end(); ++it) { if (it != vec.begin()) os << ", "; os << *it; } return os << "]"; } inline void print(void) { cout << '\n'; } template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T, class... U> inline void print(const T &x, const U &...y) { cout << x << " "; print(y...); } long long n, a, b, c; vector<string> s = {}, ans = {}; bool good = false; void rec(int idx, vector<string> &v, long long a, long long b, long long c) { if (good) return; if (idx == n) { if (a >= 0 and b >= 0 and c >= 0) { copy(v.begin(), v.end(), ans.begin()); good = true; } else { return; } } if (a < 0 or b < 0 or c < 0) return; if (s[idx] == "AB") { v.emplace_back("A"); rec(idx + 1, v, a + 1, b - 1, c); if (good) return; v.pop_back(); v.emplace_back("B"); rec(idx + 1, v, a - 1, b + 1, c); if (good) return; v.pop_back(); } else if (s[idx] == "AC") { v.emplace_back("A"); rec(idx + 1, v, a + 1, b, c - 1); if (good) return; v.pop_back(); v.emplace_back("C"); rec(idx + 1, v, a - 1, b, c + 1); if (good) return; v.pop_back(); } else { v.emplace_back("B"); rec(idx + 1, v, a, b + 1, c - 1); if (good) return; v.pop_back(); v.emplace_back("C"); rec(idx + 1, v, a, b - 1, c + 1); if (good) return; v.pop_back(); } } int main() { cin >> n >> a >> b >> c; rep(i, n) { string st; cin >> st; s.emplace_back(st); } ans.resize(n); vector<string> v = {}; rec(0, v, a, b, c); if (good) { print("Yes"); for (auto x : ans) print(x); } else { print("No"); } return 0; }
replace
0
1
0
2
-11
p02692
C++
Runtime Error
#include "bits/stdc++.h" #define Rep(i, n) for (int i = 0; i < (int)(n); i++) #define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++) #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define RREP(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--) #define FOR(i, n1, n2) for (ll i = (ll)(n1); i < (ll)(n2); i++) #define RFOR(i, n1, n2) for (ll i = ((ll)(n1)-1); i >= (ll)(n2); i--) #define all(a) (a).begin(), (a).end() #define IOS std::cin.tie(0), std::ios::sync_with_stdio(false) namespace idaten { using namespace std; using ll = int_fast64_t; using ull = uint_fast64_t; using P = std::pair<int64_t, int64_t>; template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) { is >> x; } return is; } template <class T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) { for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); } return os; } template <class V, typename T> inline void fill(V &v, const T &val) { v = val; } template <class V, typename T> inline void fill(std::vector<V> &v, const T &val) { for (V &x : v) { fill(x, val); } } template <class V, typename H> inline void resize(std::vector<V> &v, const H h) { v.resize(h); } template <class V, typename H, typename... T> inline void resize(std::vector<V> &v, const H &h, const T &...t) { v.resize(h); for (auto &x : v) { resize(x, t...); } } inline void put() {} template <class T> inline void put(const T &first) { std::cout << first << "\n"; } template <class T, class... N> inline void put(const T &first, const N &...rest) { std::cout << first << " "; put(rest...); } int f(string &s) { if (s == "AB") { return 2; } else if (s == "BC") { return 0; } else { return 1; } } void solve() { IOS; ll n, a, b, c; cin >> n >> a >> b >> c; vector<ll> d = {a, b, c}; vector<string> s(n); cin >> s; vector<int> res(n); REP(i, n) { int t1, t2, t3; int t4 = f(s[i]); if (s[i] == "AB") { t1 = 0, t2 = 1, t3 = 2; } else if (s[i] == "BC") { t1 = 1, t2 = 2, t3 = 0; } else { t1 = 0, t2 = 2, t3 = 1; } if (d[t1] == d[t2] && d[t1] == 0) { put("No"); return; } if (d[t1] == d[t2] && d[t1] == 1 && d[t3] == 0 && i < n - 1) { int t5 = f(s[i + 1]); int t6 = 3 - t4 - t5; int t7 = t1 + t2 - t6; res[i] = t6; d[t7]--; d[t6]++; } else { if (d[t1] < d[t2]) { res[i] = t1; d[t1]++; d[t2]--; } else { res[i] = t2; d[t1]--; d[t2]++; } } } put("Yes"); REP(i, n) { char c = (char)'A' + res[i]; put(c); } } } // namespace idaten int main() { idaten::solve(); return 0; }
#include "bits/stdc++.h" #define Rep(i, n) for (int i = 0; i < (int)(n); i++) #define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++) #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define RREP(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--) #define FOR(i, n1, n2) for (ll i = (ll)(n1); i < (ll)(n2); i++) #define RFOR(i, n1, n2) for (ll i = ((ll)(n1)-1); i >= (ll)(n2); i--) #define all(a) (a).begin(), (a).end() #define IOS std::cin.tie(0), std::ios::sync_with_stdio(false) namespace idaten { using namespace std; using ll = int_fast64_t; using ull = uint_fast64_t; using P = std::pair<int64_t, int64_t>; template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) { is >> x; } return is; } template <class T> inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) { for (auto itr = v.begin(); itr != v.end();) { os << (*itr) << ((++itr != v.end()) ? " " : ""); } return os; } template <class V, typename T> inline void fill(V &v, const T &val) { v = val; } template <class V, typename T> inline void fill(std::vector<V> &v, const T &val) { for (V &x : v) { fill(x, val); } } template <class V, typename H> inline void resize(std::vector<V> &v, const H h) { v.resize(h); } template <class V, typename H, typename... T> inline void resize(std::vector<V> &v, const H &h, const T &...t) { v.resize(h); for (auto &x : v) { resize(x, t...); } } inline void put() {} template <class T> inline void put(const T &first) { std::cout << first << "\n"; } template <class T, class... N> inline void put(const T &first, const N &...rest) { std::cout << first << " "; put(rest...); } int f(string &s) { if (s == "AB") { return 2; } else if (s == "BC") { return 0; } else { return 1; } } void solve() { IOS; ll n, a, b, c; cin >> n >> a >> b >> c; vector<ll> d = {a, b, c}; vector<string> s(n); cin >> s; vector<int> res(n); REP(i, n) { int t1, t2, t3; int t4 = f(s[i]); if (s[i] == "AB") { t1 = 0, t2 = 1, t3 = 2; } else if (s[i] == "BC") { t1 = 1, t2 = 2, t3 = 0; } else { t1 = 0, t2 = 2, t3 = 1; } if (d[t1] == d[t2] && d[t1] == 0) { put("No"); return; } if (d[t1] == d[t2] && d[t1] == 1 && d[t3] == 0 && i < n - 1) { int t5 = f(s[i + 1]); if (t4 == t5) { res[i] = t2; d[t1]--; d[t2]++; } else { int t6 = 3 - t4 - t5; int t7 = t1 + t2 - t6; res[i] = t6; d[t7]--; d[t6]++; } } else { if (d[t1] < d[t2]) { res[i] = t1; d[t1]++; d[t2]--; } else { res[i] = t2; d[t1]--; d[t2]++; } } } put("Yes"); REP(i, n) { char c = (char)'A' + res[i]; put(c); } } } // namespace idaten int main() { idaten::solve(); return 0; }
replace
106
111
106
118
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define ll long long #define ld long double int main() { ios::sync_with_stdio(false); cin.tie(0); int n; map<char, int> ma; cin >> n >> ma['A'] >> ma['B'] >> ma['C']; vector<string> q(n); for (int i = 0; i < n; ++i) cin >> q[i]; vector<map<char, int>> pr(n + 1); pr[0] = ma; string ans = ""; for (int i = 0; i < n; ++i) { string s = q[i]; if (ma[s[0]] == 0 && ma[s[1]] == 0) { if (i == 0) { cout << "No\n"; return 0; } assert(q[i - 1][1] != s[0] && q[i - 1][1] != s[1]); if (pr[i - 1][q[i - 1][1]] == 0) { cout << "No\n"; return 0; } ans.back() = q[i - 1][0]; pr[i][q[i - 1][1]] -= 2; pr[i][q[i - 1][0]] += 2; ma = pr[i]; char ch = 'A'; while (ch == q[i - 1][0] || ch == q[i - 1][1]) ++ch; ans.pb(ch); ++ma[ch]; --ma[q[i - 1][0]]; } else { if (ma[s[0]] == 0) { ans.pb(s[0]); ++ma[s[0]]; --ma[s[1]]; } else { ans.pb(s[1]); ++ma[s[1]]; --ma[s[0]]; } } pr[i + 1] = ma; } cout << "Yes\n"; for (auto x : ans) cout << x << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define pb push_back #define mp make_pair #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define ll long long #define ld long double int main() { ios::sync_with_stdio(false); cin.tie(0); int n; map<char, int> ma; cin >> n >> ma['A'] >> ma['B'] >> ma['C']; vector<string> q(n); for (int i = 0; i < n; ++i) cin >> q[i]; vector<map<char, int>> pr(n + 1); pr[0] = ma; string ans = ""; for (int i = 0; i < n; ++i) { string s = q[i]; if (ma[s[0]] == 0 && ma[s[1]] == 0) { if (i == 0) { cout << "No\n"; return 0; } if (q[i - 1][1] == s[0] || q[i - 1][1] == s[1]) swap(q[i - 1][1], q[i - 1][0]); if (pr[i - 1][q[i - 1][1]] == 0) { cout << "No\n"; return 0; } ans.back() = q[i - 1][0]; pr[i][q[i - 1][1]] -= 2; pr[i][q[i - 1][0]] += 2; ma = pr[i]; char ch = 'A'; while (ch == q[i - 1][0] || ch == q[i - 1][1]) ++ch; ans.pb(ch); ++ma[ch]; --ma[q[i - 1][0]]; } else { if (ma[s[0]] == 0) { ans.pb(s[0]); ++ma[s[0]]; --ma[s[1]]; } else { ans.pb(s[1]); ++ma[s[1]]; --ma[s[0]]; } } pr[i + 1] = ma; } cout << "Yes\n"; for (auto x : ans) cout << x << '\n'; return 0; }
replace
33
34
33
35
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9; const double PI = acos(-1); #define tam 220000 #define offset const ll MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int v[300]; int ans[tam]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> v['A'] >> v['B'] >> v['C']; string txt, ant; int m = v['A'] + v['B'] + v['C']; bool valid = 1; forr(i, 0, n) { cin >> txt; if (m <= 1) { if (v[txt[0]] + v[txt[1]] == 0) valid = 0; else { if (v[txt[0]] == 1) ans[i] = txt[1], v[txt[0]]--, v[txt[1]]++; else ans[i] = txt[0], v[txt[0]]++, v[txt[1]]--; } } else { if (v[txt[0]] + v[txt[1]] == 0) { if (i - 1 < 0) valid = 0; else { if (ans[i - 1] == ant[0]) { ans[i - 1] = ant[1]; v[ant[0]] -= 2, v[ant[1]] += 2; } else { ans[i - 1] = ant[0]; v[ant[1]] -= 2, v[ant[0]] += 2; } assert(v[ant[0]] >= 0); assert(v[ant[1]] >= 0); } } if (v[txt[0]] > 0) { v[txt[0]]--, v[txt[1]]++; ans[i] = txt[1]; } else { v[txt[1]]--, v[txt[0]]++; ans[i] = txt[0]; } } ant = txt; } if (valid) { cout << "Yes\n"; forr(i, 0, n) { cout << (char)ans[i] << endl; } } else cout << "No\n"; } // PLUS ULTRA!
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<ii, ll> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9; const double PI = acos(-1); #define tam 220000 #define offset const ll MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int v[300]; int ans[tam]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n >> v['A'] >> v['B'] >> v['C']; string txt, ant; int m = v['A'] + v['B'] + v['C']; bool valid = 1; forr(i, 0, n) { cin >> txt; if (m <= 1) { if (v[txt[0]] + v[txt[1]] == 0) valid = 0; else { if (v[txt[0]] == 1) ans[i] = txt[1], v[txt[0]]--, v[txt[1]]++; else ans[i] = txt[0], v[txt[0]]++, v[txt[1]]--; } } else { if (v[txt[0]] + v[txt[1]] == 0) { if (i - 1 < 0) valid = 0; else { if (ans[i - 1] == ant[0]) { ans[i - 1] = ant[1]; v[ant[0]] -= 2, v[ant[1]] += 2; } else { ans[i - 1] = ant[0]; v[ant[1]] -= 2, v[ant[0]] += 2; } if (v[ant[0]] < 0 || v[ant[1]] < 0) valid = 0; // assert(v[ant[0]]>=0); // assert(v[ant[1]]>=0); } } if (v[txt[0]] > 0) { v[txt[0]]--, v[txt[1]]++; ans[i] = txt[1]; } else { v[txt[1]]--, v[txt[0]]++; ans[i] = txt[0]; } } ant = txt; } if (valid) { cout << "Yes\n"; forr(i, 0, n) { cout << (char)ans[i] << endl; } } else cout << "No\n"; } // PLUS ULTRA!
replace
66
68
66
70
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) begin(v), end(v) #define fi first #define se second template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll << 30; constexpr ll longINF = 1ll << 60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// int N; vector<int> C; int dp[112345][4][4][4]; vector<string> S; bool dfs(int p, vector<int> c) { REP(i, 3) if (c[i] < 0) return false; if (p == N) return true; int &res = dp[p][c[0]][c[1]][c[2]]; if (res != -1) return res; res = 0; REP(i, 2) { vector<int> nc = c; nc[S[p][0] - 'A']++; nc[S[p][1] - 'A']--; res |= dfs(p + 1, nc); swap(S[p][0], S[p][1]); } return res; } int main() { cin >> N; C.resize(3); REP(i, 3) cin >> C[i]; S.resize(N); REP(i, N) cin >> S[i]; memset(dp, -1, sizeof(dp)); bool ok = dfs(0, C); puts([&] { return ok; }() ? "Yes" : "No"); if (ok) { vector<string> ans; REP(i, N) { REP(j, 2) { vector<int> nc = C; nc[S[i][0] - 'A']++; nc[S[i][1] - 'A']--; if (dfs(i + 1, nc)) { ans.emplace_back(S[i].substr(0, 1)); C = nc; break; } swap(S[i][0], S[i][1]); } } for (string &s : ans) cout << s << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) begin(v), end(v) #define fi first #define se second template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll << 30; constexpr ll longINF = 1ll << 60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// int N; vector<int> C; int dp[112345][4][4][4]; vector<string> S; bool dfs(int p, vector<int> c) { REP(i, 3) if (c[i] < 0) return false; if (p == N) return true; int &res = dp[p][c[0]][c[1]][c[2]]; if (res != -1) return res; res = 0; REP(i, 2) { vector<int> nc = c; nc[S[p][0] - 'A']++; nc[S[p][1] - 'A']--; res |= dfs(p + 1, nc); swap(S[p][0], S[p][1]); } return res; } int main() { cin >> N; C.resize(3); REP(i, 3) { cin >> C[i]; if (C[i] > 3) C[i] = 3; } S.resize(N); REP(i, N) cin >> S[i]; memset(dp, -1, sizeof(dp)); bool ok = dfs(0, C); puts([&] { return ok; }() ? "Yes" : "No"); if (ok) { vector<string> ans; REP(i, N) { REP(j, 2) { vector<int> nc = C; nc[S[i][0] - 'A']++; nc[S[i][1] - 'A']--; if (dfs(i + 1, nc)) { ans.emplace_back(S[i].substr(0, 1)); C = nc; break; } swap(S[i][0], S[i][1]); } } for (string &s : ans) cout << s << endl; } return 0; }
replace
57
58
57
62
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int n, a, b, c; cin >> n >> a >> b >> c; vector<string> s(n); vector<char> ans(n); rep(i, n) cin >> s.at(i); bool ok = true; auto next = [&](int i, int &x, int &y) { if (x + y == 0) { ok = false; return ok; } if (x == 0) { ans.at(i) = s.at(i).at(0); x++; y--; } else if (y == 0) { ans.at(i) = s.at(i).at(1); x--; y++; } else { if (s.at(i + 1).find(s.at(i).at(0)) != string::npos && i < n - 1) { ans.at(i) = s.at(i).at(0); x++; y--; } else { ans.at(i) = s.at(i).at(1); x--; y++; } } return true; }; rep(i, n) { if (s.at(i) == "AB") { if (!next(i, a, b)) break; } else if (s.at(i) == "AC") { if (!next(i, a, c)) break; } else if (s.at(i) == "BC") { if (!next(i, b, c)) break; } } if (ok) { cout << "Yes" << endl; rep(i, n) cout << ans.at(i) << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int n, a, b, c; cin >> n >> a >> b >> c; vector<string> s(n); vector<char> ans(n); rep(i, n) cin >> s.at(i); bool ok = true; auto next = [&](int i, int &x, int &y) { if (x + y == 0) { ok = false; return ok; } if (x == 0) { ans.at(i) = s.at(i).at(0); x++; y--; } else if (y == 0) { ans.at(i) = s.at(i).at(1); x--; y++; } else { if (i < n - 1 && s.at(i + 1).find(s.at(i).at(0)) != string::npos) { ans.at(i) = s.at(i).at(0); x++; y--; } else { ans.at(i) = s.at(i).at(1); x--; y++; } } return true; }; rep(i, n) { if (s.at(i) == "AB") { if (!next(i, a, b)) break; } else if (s.at(i) == "AC") { if (!next(i, a, c)) break; } else if (s.at(i) == "BC") { if (!next(i, b, c)) break; } } if (ok) { cout << "Yes" << endl; rep(i, n) cout << ans.at(i) << endl; } else { cout << "No" << endl; } return 0; }
replace
28
29
28
29
0
p02692
C++
Memory Limit Exceeded
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i32 = int32_t; using i64 = int64_t; constexpr char newl = '\n'; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, b) FOR(i, 0, b) #define RFO(i, a, b) for (int i = ((b)-1); i >= (a); i--) #define RF0(i, b) RFO(i, 0, b) // #define F first // #define S second #define debug(x) cout << #x << ": " << x << '\n'; #if 1 enum class Match : u8 { AB, AC, BC, }; string calc(int A, int B, int C, const vector<Match> &ms, int start = 0) { string result; result.reserve(ms.size()); FOR(i, start, ms.size()) { switch (ms[i]) { case Match::AB: if (A > B || A > 1) { A--; B++; result += 'B'; } else if (A < B) { A++; B--; result += 'A'; } else if (A == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'A'; } else { auto r = calc(A + 1, B - 1, C, ms, i + 1); if (r.size() > 0) { return result + 'A' + r; } r = calc(A - 1, B + 1, C, ms, i + 1); if (r.size() > 0) { return result + 'B' + r; } return ""; } } break; case Match::AC: if (A > C || A > 1) { A--; C++; result += 'C'; } else if (A < C) { A++; C--; result += 'A'; } else if (A == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'A'; } else { auto r = calc(A + 1, B, C - 1, ms, i + 1); if (r.size() > 0) { return result + 'A' + r; } r = calc(A - 1, B, C + 1, ms, i + 1); if (r.size() > 0) { return result + 'C' + r; } return ""; } } break; case Match::BC: if (B > C || B > 1) { B--; C++; result += 'C'; } else if (B < C) { B++; C--; result += 'B'; } else if (B == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'B'; } else { auto r = calc(A, B + 1, C - 1, ms, i + 1); if (r.size() > 0) { return result + 'B' + r; } r = calc(A, B - 1, C + 1, ms, i + 1); if (r.size() > 0) { return result + 'C' + r; } return ""; } } break; } } return result; } // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, A, B, C; cin >> N >> A >> B >> C; vector<Match> ms; ms.reserve(N); F0R(i, N) { string s; cin >> s; ms.push_back(s == "AB" ? Match::AB : s == "AC" ? Match::AC : Match::BC); } string result = calc(A, B, C, ms); if (result == "") { cout << "No" << newl; } else { cout << "Yes" << newl; for (auto c : result) { cout << c << newl; } } } #endif
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i32 = int32_t; using i64 = int64_t; constexpr char newl = '\n'; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, b) FOR(i, 0, b) #define RFO(i, a, b) for (int i = ((b)-1); i >= (a); i--) #define RF0(i, b) RFO(i, 0, b) // #define F first // #define S second #define debug(x) cout << #x << ": " << x << '\n'; #if 1 enum class Match : u8 { AB, AC, BC, }; string calc(int A, int B, int C, const vector<Match> &ms, int start = 0) { string result; FOR(i, start, ms.size()) { switch (ms[i]) { case Match::AB: if (A > B || A > 1) { A--; B++; result += 'B'; } else if (A < B) { A++; B--; result += 'A'; } else if (A == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'A'; } else { auto r = calc(A + 1, B - 1, C, ms, i + 1); if (r.size() > 0) { return result + 'A' + r; } r = calc(A - 1, B + 1, C, ms, i + 1); if (r.size() > 0) { return result + 'B' + r; } return ""; } } break; case Match::AC: if (A > C || A > 1) { A--; C++; result += 'C'; } else if (A < C) { A++; C--; result += 'A'; } else if (A == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'A'; } else { auto r = calc(A + 1, B, C - 1, ms, i + 1); if (r.size() > 0) { return result + 'A' + r; } r = calc(A - 1, B, C + 1, ms, i + 1); if (r.size() > 0) { return result + 'C' + r; } return ""; } } break; case Match::BC: if (B > C || B > 1) { B--; C++; result += 'C'; } else if (B < C) { B++; C--; result += 'B'; } else if (B == 0) { return ""; } else { if (i == ms.size() - 1) { result += 'B'; } else { auto r = calc(A, B + 1, C - 1, ms, i + 1); if (r.size() > 0) { return result + 'B' + r; } r = calc(A, B - 1, C + 1, ms, i + 1); if (r.size() > 0) { return result + 'C' + r; } return ""; } } break; } } return result; } // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, A, B, C; cin >> N >> A >> B >> C; vector<Match> ms; ms.reserve(N); F0R(i, N) { string s; cin >> s; ms.push_back(s == "AB" ? Match::AB : s == "AC" ? Match::AC : Match::BC); } string result = calc(A, B, C, ms); if (result == "") { cout << "No" << newl; } else { cout << "Yes" << newl; for (auto c : result) { cout << c << newl; } } } #endif
delete
41
42
41
41
MLE
p02692
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); int n, a, b, c; cin >> n >> a >> b >> c; vector<string> S(n); string alpha; REP(i, n) { string s; cin >> s; S[i] = s; } if (a + b + c != 2) { REP(i, n) { if (S[i] == "AB") { if (a < b) { a++; b--; alpha.push_back('A'); } else { a--; b++; alpha.push_back('B'); } } else if (S[i] == "BC") { if (b < c) { b++; c--; alpha.push_back('B'); } else { b--; c++; alpha.push_back('C'); } } else if (S[i] == "AC") { if (a < c) { a++; c--; alpha.push_back('A'); } else { a--; c++; alpha.push_back('C'); } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; REP(i, n) { cout << alpha[i] << endl; } } else { REP(i, n - 1) { if (S[i] == "AB") { if (a == 0) { a++; b--; alpha.push_back('A'); } else if (b == 0) { a--; b++; alpha.push_back('B'); } else if (a == 1 && b == 1) { if (S[i + 1] == "BC") { a--; b++; alpha.push_back('B'); } else { a++; b--; alpha.push_back('A'); } } } if (S[i] == "BC") { if (b == 0) { b++; c--; alpha.push_back('B'); } else if (c == 0) { b--; c++; alpha.push_back('C'); } else if (c == 1 && b == 1) { if (S[i + 1] == "AB") { c--; b++; alpha.push_back('B'); } else { c++; b--; alpha.push_back('C'); } } } if (S[i] == "AC") { if (a == 0) { a++; c--; alpha.push_back('A'); } else if (c == 0) { a--; c++; alpha.push_back('C'); } else if (a == 1 && c == 1) { if (S[i + 1] == "BC") { a--; c++; alpha.push_back('C'); } else { a++; c--; alpha.push_back('A'); } } } } if (S[n - 1] == "AB") { if (a < b) { a++; b--; alpha.push_back('A'); } else { a--; b++; alpha.push_back('B'); } } else if (S[n - 1] == "BC") { if (b < c) { b++; c--; alpha.push_back('B'); } else { b--; c++; alpha.push_back('C'); } } else if (S[n - 1] == "AC") { if (a < c) { a++; c--; alpha.push_back('A'); } else { a--; c++; alpha.push_back('C'); } } cout << "Yes" << endl; REP(i, n) { cout << alpha[i] << endl; } } }
#include <algorithm> #include <functional> #include <iostream> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); // cout << fixed << setprecision(15); int n, a, b, c; cin >> n >> a >> b >> c; vector<string> S(n); string alpha; REP(i, n) { string s; cin >> s; S[i] = s; } if (a + b + c != 2) { REP(i, n) { if (S[i] == "AB") { if (a < b) { a++; b--; alpha.push_back('A'); } else { a--; b++; alpha.push_back('B'); } } else if (S[i] == "BC") { if (b < c) { b++; c--; alpha.push_back('B'); } else { b--; c++; alpha.push_back('C'); } } else if (S[i] == "AC") { if (a < c) { a++; c--; alpha.push_back('A'); } else { a--; c++; alpha.push_back('C'); } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; REP(i, n) { cout << alpha[i] << endl; } } else { REP(i, n - 1) { if (S[i] == "AB") { if (a == 0) { a++; b--; alpha.push_back('A'); } else if (b == 0) { a--; b++; alpha.push_back('B'); } else if (a == 1 && b == 1) { if (S[i + 1] == "BC") { a--; b++; alpha.push_back('B'); } else { a++; b--; alpha.push_back('A'); } } } if (S[i] == "BC") { if (b == 0) { b++; c--; alpha.push_back('B'); } else if (c == 0) { b--; c++; alpha.push_back('C'); } else if (c == 1 && b == 1) { if (S[i + 1] == "AB") { c--; b++; alpha.push_back('B'); } else { c++; b--; alpha.push_back('C'); } } } if (S[i] == "AC") { if (a == 0) { a++; c--; alpha.push_back('A'); } else if (c == 0) { a--; c++; alpha.push_back('C'); } else if (a == 1 && c == 1) { if (S[i + 1] == "BC") { a--; c++; alpha.push_back('C'); } else { a++; c--; alpha.push_back('A'); } } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } } if (S[n - 1] == "AB") { if (a < b) { a++; b--; alpha.push_back('A'); } else { a--; b++; alpha.push_back('B'); } } else if (S[n - 1] == "BC") { if (b < c) { b++; c--; alpha.push_back('B'); } else { b--; c++; alpha.push_back('C'); } } else if (S[n - 1] == "AC") { if (a < c) { a++; c--; alpha.push_back('A'); } else { a--; c++; alpha.push_back('C'); } } cout << "Yes" << endl; REP(i, n) { cout << alpha[i] << endl; } } }
insert
136
136
136
140
0
p02692
C++
Runtime Error
/*** author: yuji9511 ***/ #include <bits/stdc++.h> using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i, m, n) for (ll i = (m); i < (n); i++) #define rrep(i, m, n) for (ll i = (m); i >= (n); i--) #define printa(x, n) \ for (ll i = 0; i < n; i++) { \ cout << (x[i]) << " \n"[i == n - 1]; \ }; void print() {} template <class H, class... T> void print(H &&h, T &&...t) { cout << h << " \n"[sizeof...(t) == 0]; print(forward<T>(t)...); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, A, B, C; cin >> N >> A >> B >> C; string S[100010]; rep(i, 0, N) cin >> S[i]; if (A == 0 && B == 0 && C == 0) { print("No"); } else if (A + B + C == 1) { bool ok = true; vector<char> ans; rep(i, 0, N) { if (S[i] == "AB") { if (A == 0 && B == 0) { ok = false; } else { if (A == 1) ans.push_back('B'); else ans.push_back('A'); swap(A, B); } } else if (S[i] == "BC") { if (B == 0 && C == 0) { ok = false; } else { if (B == 1) ans.push_back('C'); else ans.push_back('B'); swap(B, C); } } else { if (A == 0 && C == 0) { ok = false; } else { if (A == 1) ans.push_back('C'); else ans.push_back('A'); swap(A, C); } } } if (ok) { print("Yes"); rep(i, 0, N) print(ans[i]); } else { print("No"); } } else if (A + B + C >= 3) { bool ok = true; vector<char> ans; rep(i, 0, N) { if (S[i] == "AB") { if (A + B == 0) { ok = false; } else { if (A < B) { ans.push_back('A'); A++; B--; } else { ans.push_back('B'); B++; A--; } } } else if (S[i] == "BC") { if (C + B == 0) { ok = false; } else { if (C < B) { ans.push_back('C'); C++; B--; } else { ans.push_back('B'); B++; C--; } } } else { if (A + C == 0) { ok = false; } else { if (A < C) { ans.push_back('A'); A++; C--; } else { ans.push_back('C'); C++; A--; } } } } if (ok) { print("Yes"); rep(i, 0, N) print(ans[i]); } else { print("No"); } } else { exit(1); } }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = 1e18; #define rep(i, m, n) for (ll i = (m); i < (n); i++) #define rrep(i, m, n) for (ll i = (m); i >= (n); i--) #define printa(x, n) \ for (ll i = 0; i < n; i++) { \ cout << (x[i]) << " \n"[i == n - 1]; \ }; void print() {} template <class H, class... T> void print(H &&h, T &&...t) { cout << h << " \n"[sizeof...(t) == 0]; print(forward<T>(t)...); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, A, B, C; cin >> N >> A >> B >> C; string S[100010]; rep(i, 0, N) cin >> S[i]; if (A == 0 && B == 0 && C == 0) { print("No"); } else if (A + B + C == 1) { bool ok = true; vector<char> ans; rep(i, 0, N) { if (S[i] == "AB") { if (A == 0 && B == 0) { ok = false; } else { if (A == 1) ans.push_back('B'); else ans.push_back('A'); swap(A, B); } } else if (S[i] == "BC") { if (B == 0 && C == 0) { ok = false; } else { if (B == 1) ans.push_back('C'); else ans.push_back('B'); swap(B, C); } } else { if (A == 0 && C == 0) { ok = false; } else { if (A == 1) ans.push_back('C'); else ans.push_back('A'); swap(A, C); } } } if (ok) { print("Yes"); rep(i, 0, N) print(ans[i]); } else { print("No"); } } else if (A + B + C >= 3) { bool ok = true; vector<char> ans; rep(i, 0, N) { if (S[i] == "AB") { if (A + B == 0) { ok = false; } else { if (A < B) { ans.push_back('A'); A++; B--; } else { ans.push_back('B'); B++; A--; } } } else if (S[i] == "BC") { if (C + B == 0) { ok = false; } else { if (C < B) { ans.push_back('C'); C++; B--; } else { ans.push_back('B'); B++; C--; } } } else { if (A + C == 0) { ok = false; } else { if (A < C) { ans.push_back('A'); A++; C--; } else { ans.push_back('C'); C++; A--; } } } } if (ok) { print("Yes"); rep(i, 0, N) print(ans[i]); } else { print("No"); } } else { vector<ll> pos[3]; vector<char> ans; rep(i, 0, N) { if (S[i] == "AB") pos[0].push_back(i); else if (S[i] == "BC") pos[1].push_back(i); else pos[2].push_back(i); } bool ok = true; rep(i, 0, N) { if (S[i] == "AB") { if (A + B == 0) { ok = false; } else if (A < B) { ans.push_back('A'); A++; B--; } else if (A > B) { ans.push_back('B'); B++; A--; } else { ll p1 = lower_bound(pos[1].begin(), pos[1].end(), i) - pos[1].begin(); ll p2 = lower_bound(pos[2].begin(), pos[2].end(), i) - pos[2].begin(); ll v1 = INF, v2 = INF; if (p1 != pos[1].size()) v1 = pos[1][p1]; if (p2 != pos[2].size()) v2 = pos[2][p2]; if (v1 <= v2) { ans.push_back('B'); B++; A--; } else { ans.push_back('A'); A++; B--; } } } else if (S[i] == "BC") { if (C + B == 0) { ok = false; } else if (C < B) { ans.push_back('C'); C++; B--; } else if (C > B) { ans.push_back('B'); B++; C--; } else { ll p1 = lower_bound(pos[0].begin(), pos[0].end(), i) - pos[0].begin(); ll p2 = lower_bound(pos[2].begin(), pos[2].end(), i) - pos[2].begin(); ll v1 = INF, v2 = INF; if (p1 != pos[0].size()) v1 = pos[0][p1]; if (p2 != pos[2].size()) v2 = pos[2][p2]; if (v1 <= v2) { ans.push_back('B'); B++; C--; } else { ans.push_back('C'); C++; B--; } // print(v1,v2); } // print(A,B,C); } else { if (A + C == 0) { ok = false; } else if (A < C) { ans.push_back('A'); A++; C--; } else if (A > C) { ans.push_back('C'); C++; A--; } else { ll p1 = lower_bound(pos[0].begin(), pos[0].end(), i) - pos[0].begin(); ll p2 = lower_bound(pos[1].begin(), pos[1].end(), i) - pos[1].begin(); ll v1 = INF, v2 = INF; if (p1 != pos[0].size()) v1 = pos[0][p1]; if (p2 != pos[1].size()) v2 = pos[1][p2]; if (v1 <= v2) { ans.push_back('A'); A++; C--; } else { ans.push_back('C'); C++; A--; } } } } if (ok) { print("Yes"); rep(i, 0, N) print(ans[i]); } else { print("No"); } } }
replace
125
126
125
239
0
p02692
C++
Time Limit Exceeded
// R<3S #include <bits/stdc++.h> #define DECIMAL(n) \ std::cout << std::fixed; \ std::cout << std::setprecision(n); #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define vecmax(v) max_element(all(v)) #define vecmin(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define int long long #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(x) for (auto i : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define invect(data, n) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ } #define inset(data, n) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.insert(tmp); \ } #define ll long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define mll map<ll, ll> #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; int flag = 0; void find(int i, vector<string> &v, int a, int b, int c, string &ans) { // if(flag)return; if (a < 0 || b < 0 || c < 0) return; if (i == sz(v) && a >= 0 && b >= 0 && c >= 0) { if (flag == 0) { cout << "Yes\n"; rep(j, sz(ans)) cout << ans[j] << endl; flag++; } return; } if (v[i] == "AB") { ans += 'B'; find(i + 1, v, a - 1, b + 1, c, ans); ans.pop_back(); ans += 'A'; find(i + 1, v, a + 1, b - 1, c, ans); ans.pop_back(); } else if (v[i] == "BC") { ans += 'B'; find(i + 1, v, a, b + 1, c - 1, ans); ans.pop_back(); ans += 'C', find(i + 1, v, a, b - 1, c + 1, ans); ans.pop_back(); } else if (v[i] == "AC") { ans += 'C'; find(i + 1, v, a - 1, b, c + 1, ans); ans.pop_back(); ans += 'A'; find(i + 1, v, a + 1, b, c - 1, ans); ans.pop_back(); } } void solve() { vector<string> v; int n, a, b, c; cin >> n >> a >> b >> c; rep(i, n) { string s; cin >> s; v.pb(s); } string ans = ""; find(0, v, a, b, c, ans); if (flag == 0) cout << "No"; } signed main() { FAST int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// R<3S #include <bits/stdc++.h> #define DECIMAL(n) \ std::cout << std::fixed; \ std::cout << std::setprecision(n); #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define vecmax(v) max_element(all(v)) #define vecmin(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define int long long #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(x) for (auto i : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define invect(data, n) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ } #define inset(data, n) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.insert(tmp); \ } #define ll long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define mll map<ll, ll> #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; int flag = 0; void find(int i, vector<string> &v, int a, int b, int c, string &ans) { if (flag) return; if (a < 0 || b < 0 || c < 0) return; if (i == sz(v) && a >= 0 && b >= 0 && c >= 0) { if (flag == 0) { cout << "Yes\n"; rep(j, sz(ans)) cout << ans[j] << endl; flag++; } return; } if (v[i] == "AB") { ans += 'B'; find(i + 1, v, a - 1, b + 1, c, ans); ans.pop_back(); ans += 'A'; find(i + 1, v, a + 1, b - 1, c, ans); ans.pop_back(); } else if (v[i] == "BC") { ans += 'B'; find(i + 1, v, a, b + 1, c - 1, ans); ans.pop_back(); ans += 'C', find(i + 1, v, a, b - 1, c + 1, ans); ans.pop_back(); } else if (v[i] == "AC") { ans += 'C'; find(i + 1, v, a - 1, b, c + 1, ans); ans.pop_back(); ans += 'A'; find(i + 1, v, a + 1, b, c - 1, ans); ans.pop_back(); } } void solve() { vector<string> v; int n, a, b, c; cin >> n >> a >> b >> c; rep(i, n) { string s; cin >> s; v.pb(s); } string ans = ""; find(0, v, a, b, c, ans); if (flag == 0) cout << "No"; } signed main() { FAST int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
78
79
78
80
TLE
p02692
C++
Time Limit Exceeded
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, A, B, C; cin >> N >> A >> B >> C; vector<string> s(N); cin >> s; string x = ""; string res; bool flag = true; auto dfs = [&](auto &&self, ll A, ll B, ll C, ll ct = 0) { if (A < 0 or B < 0 or C < 0) return; if (ct == N) { flag = false; res = x; return; } if (s[ct] == "AB") { x += "A"; self(self, A + 1, B - 1, C, ct + 1); x.back() = 'B'; self(self, A - 1, B + 1, C, ct + 1); x.pop_back(); } if (s[ct] == "BC") { x += "B"; self(self, A, B + 1, C - 1, ct + 1); x.back() = 'C'; self(self, A, B - 1, C + 1, ct + 1); x.pop_back(); } if (s[ct] == "AC") { x += "A"; self(self, A + 1, B, C - 1, ct + 1); x.back() = 'C'; self(self, A - 1, B, C + 1, ct + 1); x.pop_back(); } }; dfs(dfs, A, B, C); if (!flag) { print("Yes"); for (auto c : res) print(c); } else { print("No"); } return 0; }
#include <bits/stdc++.h> const long long INF = 1LL << 60; const long long MOD = 1000000007; const double PI = acos(-1.0); #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep(i, n) for (ll i = (n - 1); i >= 0; --i) #define perm(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define to_s to_string #define len(v) (ll) v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define print(x) cout << (x) << '\n' #define drop(x) cout << (x) << '\n', exit(0) #define debug(x) cout << #x << ": " << (x) << '\n' using namespace std; using ll = long long; typedef pair<ll, ll> P; typedef vector<ll> vec; typedef vector<vector<ll>> vec2; typedef vector<vector<vector<ll>>> vec3; template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class S, class T> inline bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } inline ll msb(ll v) { return 1 << (31 - __builtin_clzll(v)); } inline ll devc(ll x, ll y) { return (x + y - 1) / y; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2, typename T3> ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) { os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; } template <typename T1, typename T2, typename T3> istream &operator>>(istream &is, tuple<T1, T2, T3> &t) { is >> get<0>(t) >> get<1>(t) >> get<2>(t); return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } /*--------------------------------- Tools * ------------------------------------------*/ template <typename T> vector<T> cumsum(const vector<T> &X) { vector<T> res(X.size() + 1, 0); for (int i = 0; i < X.size(); ++i) res[i + 1] += res[i] + X[i]; return res; } template <typename S, typename T, typename F> pair<T, T> bisearch(S left, T right, F f) { while (abs(right - left) > 1) { T mid = (right + left) / 2; if (f(mid)) right = mid; else left = mid; } return {left, right}; } template <typename S, typename T, typename F> double trisearch(S left, T right, F f, int maxLoop = 90) { double low = left, high = right; while (maxLoop--) { double mid_left = high / 3 + low * 2 / 3; double mid_right = high * 2 / 3 + low / 3; if (f(mid_left) >= f(mid_right)) low = mid_left; else high = mid_right; } return (low + high) * 0.5; } /*------------------------------- Main Code Here * -----------------------------------------*/ int main() { ll N, A, B, C; cin >> N >> A >> B >> C; vector<string> s(N); cin >> s; string x = ""; string res; bool flag = true; auto dfs = [&](auto &&self, ll A, ll B, ll C, ll ct = 0) { if (!flag) return; if (A < 0 or B < 0 or C < 0) return; if (ct == N) { flag = false; res = x; return; } if (s[ct] == "AB") { x += "A"; self(self, A + 1, B - 1, C, ct + 1); x.back() = 'B'; self(self, A - 1, B + 1, C, ct + 1); x.pop_back(); } if (s[ct] == "BC") { x += "B"; self(self, A, B + 1, C - 1, ct + 1); x.back() = 'C'; self(self, A, B - 1, C + 1, ct + 1); x.pop_back(); } if (s[ct] == "AC") { x += "A"; self(self, A + 1, B, C - 1, ct + 1); x.back() = 'C'; self(self, A - 1, B, C + 1, ct + 1); x.pop_back(); } }; dfs(dfs, A, B, C); if (!flag) { print("Yes"); for (auto c : res) print(c); } else { print("No"); } return 0; }
insert
139
139
139
141
TLE
p02692
C++
Runtime Error
#undef NDEBUG #include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<double> vd; typedef vector<vd> vdd; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) #define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i) #define RREP(i, x) RFOR(i, x, 0) #define ALL(a) a.begin(), a.end() #define pb push_back #define debug_print(x...) \ cerr << "line " << __LINE__ << " : "; \ debug_print_in(x); template <typename First> void debug_print_in(First first) { cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest) { cerr << first << " "; debug_print_in(rest...); return; } void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } template <typename First> void OUT(First first) { cout << first << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } template <class t, class u> void chmax(t &a, u b) { if (a < b) a = b; }; template <class t, class u> void chmin(t &a, u b) { if (a > b) a = b; }; int popcount(int t) { return __builtin_popcount(t); } // GCC int popcount(ll t) { return __builtin_popcountll(t); } // GCC template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cerr << VEC[i] << " "; } cerr << endl; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cerr << MAT[i][j] << " "; } cerr << endl; } } ; ll N, A, B, C; ll ABC; vll s; vvll dp; ll dp_search(ll index) { if (index >= N) { return index; } if (s.at(index) == 1) { dp[index + 1][0] = dp[index][5]; dp[index + 1][1] = dp[index][5]; dp[index + 1][2] = 0; dp[index + 1][3] = dp[index][4]; dp[index + 1][4] = dp[index][3]; dp[index + 1][5] = dp[index][0] | dp[index][1]; } else if (s.at(index) == 2) { dp[index + 1][0] = dp[index][4]; dp[index + 1][1] = 0; dp[index + 1][2] = dp[index][4]; dp[index + 1][3] = dp[index][5]; dp[index + 1][4] = dp[index][0] | dp[index][2]; dp[index + 1][5] = dp[index][3]; } else if (s.at(index) == 3) { dp[index + 1][0] = 0; dp[index + 1][1] = dp[index][3]; dp[index + 1][2] = dp[index][3]; dp[index + 1][3] = dp[index][1] | dp[index][2]; dp[index + 1][4] = dp[index][5]; dp[index + 1][5] = dp[index][4]; } ll status = -1; for (int k = 0; k < 6; ++k) { if (dp[index + 1][k] > 0) status = k; } if (status < 0) return index; return dp_search(index + 1); } vvll hoge = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}}; void rev(vvll &ans, ll index, ll state) { ans.push_back(hoge.at(state)); if (index < 0) return; ll new_state = -1; if (s.at(index) == 1) { switch (state) { case 0: new_state = 5; break; case 1: new_state = 5; break; case 2: break; case 3: new_state = 4; break; case 4: new_state = 3; break; case 5: if (dp.at(index).at(0) > 0) { new_state = 0; } else { new_state = 1; } break; } } else if (s.at(index) == 2) { switch (state) { case 0: new_state = 4; break; case 1: break; case 2: new_state = 4; break; case 3: new_state = 5; break; case 4: if (dp.at(index).at(0) > 0) { new_state = 0; } else { new_state = 2; } break; case 5: new_state = 3; break; } } else { switch (state) { case 0: break; case 1: new_state = 3; break; case 2: new_state = 3; break; case 3: if (dp.at(index).at(1) > 0) { new_state = 1; } else { new_state = 2; } break; case 4: new_state = 5; break; case 5: new_state = 4; break; } } rev(ans, index - 1, new_state); return; } vvll tmp(0); // vvll search(void){ void search(void) { /* { ll status = -1; for(ll k=0; k<6; ++k){ if(dp[0][k] > 0) status = k; } assert(status>=0); } */ ll val = dp_search(0); assert(val > N - 1); ll state = -1; REP(i, 6) { if (dp[N][i] > 0) { state = i; } } // assert(state>=0); if (state == -1) return; rev(tmp, N - 1, state); reverse(ALL(tmp)); return; } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) IN(N, A, B, C); ll A_init = A; ll B_init = B; ll C_init = C; ABC = A + B + C; // ABC = 1 -> do // ABC >= 3 -> go lower // ABC == 2 -> ? s.resize(N + 1, -1); dp.resize(N + 10, vll(6, 0)); if (A == 2 && B == 0 && C == 0) { dp[0][0] = 1; } else if (A == 0 && B == 2 && C == 0) { dp[0][1] = 1; } else if (A == 0 && B == 0 && C == 2) { dp[0][2] = 1; } else if (A == 0 && B == 1 && C == 1) { dp[0][3] = 1; } else if (A == 1 && B == 0 && C == 1) { dp[0][4] = 1; } else if (A == 1 && B == 1 && C == 0) { dp[0][5] = 1; } REP(i, N) { string str; IN(str); if (str == "AB") { s[i] = 1; } else if (str == "AC") { s[i] = 2; } else { s[i] = 3; } } vll ans(N, -1); if (ABC <= 1 || ABC >= 3) { //{{{ REP(i, N) { switch (s[i]) { case 1: if (A == 0 && B == 0) { OUT("No"); return 0; } if (A > B) { A--; B++; ans[i] = 1; } else { A++; B--; ans[i] = 0; } break; case 2: if (A == 0 && C == 0) { OUT("No"); return 0; } if (A > C) { A--; C++; ans[i] = 2; } else { A++; C--; ans[i] = 0; } break; case 3: if (B == 0 && C == 0) { OUT("No"); return 0; } if (B > C) { B--; C++; ans[i] = 2; } else { B++; C--; ans[i] = 1; } } } //}}} } else { // vvll tmp = search(); search(); // assert(tmp.size()>0); if (tmp.size() == 0) { OUT("No"); return 0; } // mat_print(dp); // mat_print(tmp); for (ll i = 0; i < N; ++i) { REP(j, 3) { if (tmp.at(i + 1).at(j) - tmp.at(i).at(j) > 0) { ans[i] = j; break; } } } } printf("Yes\n"); // debug_print(A_init, B_init, C_init); REP(i, N) { if (ans[i] == 0) { printf("A\n"); A_init++; if (s[i] == 1) B_init--; else C_init--; } else if (ans[i] == 1) { printf("B\n"); B_init++; if (s[i] == 1) A_init--; else C_init--; } else if (ans[i] == 2) { printf("C\n"); C_init++; if (s[i] == 2) A_init--; else B_init--; } // debug_print(A_init, B_init, C_init); } return 0; }
#undef NDEBUG #include <algorithm> #include <cassert> #include <cstdio> #include <cstdlib> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vector<vector<bool>>> vvvb; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<double> vd; typedef vector<vd> vdd; #define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i) #define REP(i, y) FOR(i, 0, y) #define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i) #define RREP(i, x) RFOR(i, x, 0) #define ALL(a) a.begin(), a.end() #define pb push_back #define debug_print(x...) \ cerr << "line " << __LINE__ << " : "; \ debug_print_in(x); template <typename First> void debug_print_in(First first) { cerr << first << endl; return; } template <typename First, typename... Rest> void debug_print_in(First first, Rest... rest) { cerr << first << " "; debug_print_in(rest...); return; } void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } template <typename First> void OUT(First first) { cout << first << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } template <class t, class u> void chmax(t &a, u b) { if (a < b) a = b; }; template <class t, class u> void chmin(t &a, u b) { if (a > b) a = b; }; int popcount(int t) { return __builtin_popcount(t); } // GCC int popcount(ll t) { return __builtin_popcountll(t); } // GCC template <typename T> void vec_print(vector<T> VEC) { REP(i, VEC.size()) { cerr << VEC[i] << " "; } cerr << endl; }; template <typename T> void mat_print(vector<vector<T>> MAT){ REP(i, MAT.size()){REP(j, MAT[i].size()){cerr << MAT[i][j] << " "; } cerr << endl; } } ; ll N, A, B, C; ll ABC; vll s; vvll dp; ll dp_search(ll index) { if (index >= N) { return index; } if (s.at(index) == 1) { dp[index + 1][0] = dp[index][5]; dp[index + 1][1] = dp[index][5]; dp[index + 1][2] = 0; dp[index + 1][3] = dp[index][4]; dp[index + 1][4] = dp[index][3]; dp[index + 1][5] = dp[index][0] | dp[index][1]; } else if (s.at(index) == 2) { dp[index + 1][0] = dp[index][4]; dp[index + 1][1] = 0; dp[index + 1][2] = dp[index][4]; dp[index + 1][3] = dp[index][5]; dp[index + 1][4] = dp[index][0] | dp[index][2]; dp[index + 1][5] = dp[index][3]; } else if (s.at(index) == 3) { dp[index + 1][0] = 0; dp[index + 1][1] = dp[index][3]; dp[index + 1][2] = dp[index][3]; dp[index + 1][3] = dp[index][1] | dp[index][2]; dp[index + 1][4] = dp[index][5]; dp[index + 1][5] = dp[index][4]; } ll status = -1; for (int k = 0; k < 6; ++k) { if (dp[index + 1][k] > 0) status = k; } if (status < 0) return index; return dp_search(index + 1); } vvll hoge = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}}; void rev(vvll &ans, ll index, ll state) { ans.push_back(hoge.at(state)); if (index < 0) return; ll new_state = -1; if (s.at(index) == 1) { switch (state) { case 0: new_state = 5; break; case 1: new_state = 5; break; case 2: break; case 3: new_state = 4; break; case 4: new_state = 3; break; case 5: if (dp.at(index).at(0) > 0) { new_state = 0; } else { new_state = 1; } break; } } else if (s.at(index) == 2) { switch (state) { case 0: new_state = 4; break; case 1: break; case 2: new_state = 4; break; case 3: new_state = 5; break; case 4: if (dp.at(index).at(0) > 0) { new_state = 0; } else { new_state = 2; } break; case 5: new_state = 3; break; } } else { switch (state) { case 0: break; case 1: new_state = 3; break; case 2: new_state = 3; break; case 3: if (dp.at(index).at(1) > 0) { new_state = 1; } else { new_state = 2; } break; case 4: new_state = 5; break; case 5: new_state = 4; break; } } rev(ans, index - 1, new_state); return; } vvll tmp(0); // vvll search(void){ void search(void) { /* { ll status = -1; for(ll k=0; k<6; ++k){ if(dp[0][k] > 0) status = k; } assert(status>=0); } */ ll val = dp_search(0); // assert(val > N-1); ll state = -1; REP(i, 6) { if (dp[N][i] > 0) { state = i; } } // assert(state>=0); if (state == -1) return; rev(tmp, N - 1, state); reverse(ALL(tmp)); return; } int main() { cin.tie(0); // cut the cin and cout (default, std::flush is performed after // std::cin) ios::sync_with_stdio( false); // cut the iostream and stdio (DON'T endl; BUT "\n";) IN(N, A, B, C); ll A_init = A; ll B_init = B; ll C_init = C; ABC = A + B + C; // ABC = 1 -> do // ABC >= 3 -> go lower // ABC == 2 -> ? s.resize(N + 1, -1); dp.resize(N + 10, vll(6, 0)); if (A == 2 && B == 0 && C == 0) { dp[0][0] = 1; } else if (A == 0 && B == 2 && C == 0) { dp[0][1] = 1; } else if (A == 0 && B == 0 && C == 2) { dp[0][2] = 1; } else if (A == 0 && B == 1 && C == 1) { dp[0][3] = 1; } else if (A == 1 && B == 0 && C == 1) { dp[0][4] = 1; } else if (A == 1 && B == 1 && C == 0) { dp[0][5] = 1; } REP(i, N) { string str; IN(str); if (str == "AB") { s[i] = 1; } else if (str == "AC") { s[i] = 2; } else { s[i] = 3; } } vll ans(N, -1); if (ABC <= 1 || ABC >= 3) { //{{{ REP(i, N) { switch (s[i]) { case 1: if (A == 0 && B == 0) { OUT("No"); return 0; } if (A > B) { A--; B++; ans[i] = 1; } else { A++; B--; ans[i] = 0; } break; case 2: if (A == 0 && C == 0) { OUT("No"); return 0; } if (A > C) { A--; C++; ans[i] = 2; } else { A++; C--; ans[i] = 0; } break; case 3: if (B == 0 && C == 0) { OUT("No"); return 0; } if (B > C) { B--; C++; ans[i] = 2; } else { B++; C--; ans[i] = 1; } } } //}}} } else { // vvll tmp = search(); search(); // assert(tmp.size()>0); if (tmp.size() == 0) { OUT("No"); return 0; } // mat_print(dp); // mat_print(tmp); for (ll i = 0; i < N; ++i) { REP(j, 3) { if (tmp.at(i + 1).at(j) - tmp.at(i).at(j) > 0) { ans[i] = j; break; } } } } printf("Yes\n"); // debug_print(A_init, B_init, C_init); REP(i, N) { if (ans[i] == 0) { printf("A\n"); A_init++; if (s[i] == 1) B_init--; else C_init--; } else if (ans[i] == 1) { printf("B\n"); B_init++; if (s[i] == 1) A_init--; else C_init--; } else if (ans[i] == 2) { printf("C\n"); C_init++; if (s[i] == 2) A_init--; else B_init--; } // debug_print(A_init, B_init, C_init); } return 0; }
replace
235
236
235
236
0
p02692
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) #define sz(v) ((int)v.size()) using namespace std; using i64 = long long; using f80 = long double; using vi32 = vector<int>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << endl; exit(0); } inline void no() { cout << "No" << endl; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { x = max(x, y); } template <typename T> inline void amin(T &x, T y) { x = min(x, y); } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } int dpl[100001][4][4][4]; void solve() { int n, a, b, c; cin >> n >> a >> b >> c; vstr s(n); cin >> s; amin(a, 2); amin(b, 2); amin(c, 2); dpl[0][a][b][c] = 1; rep(i, n) repc(j, 3) repc(k, 3) repc(l, 3) { if (dpl[i][j][k][l] == 0) continue; if (s[i] == "AB") { if (j > 0) dpl[i + 1][j - 1][k + 1][l] = 1; if (k > 0) dpl[i + 1][j + 1][k - 1][l] = 1; } else if (s[i] == "BC") { if (k > 0) dpl[i + 1][j][k - 1][l + 1] = 1; if (l > 0) dpl[i + 1][j][k + 1][l - 1] = 1; } else { if (j > 0) dpl[i + 1][j - 1][k][l + 1] = 1; if (l > 0) dpl[i + 1][j + 1][k][l - 1] = 1; } } bool ok = false; int nj, nk, nl; repc(j, 3) repc(k, 3) repc(l, 3) { if (!ok && dpl[n][j][k][l]) { ok = true; nj = j, nk = k, nl = l; } } if (!ok) { cout << "No" << endl; return; } string ans; while (sz(ans) < n) { int i = n - sz(ans) - 1; int j = nj, k = nk, l = nl; if (s[i] == "AB") { if (j > 0 && dpl[i][j - 1][k + 1][l]) { nj = j - 1, nk = k + 1, nl = l, ans += 'A'; } else if (k > 0 && dpl[i][j + 1][k - 1][l]) { nj = j + 1, nk = k - 1, nl = l, ans += 'B'; } } else if (s[i] == "BC") { if (k > 0 && dpl[i][j][k - 1][l + 1]) { nj = j, nk = k - 1, nl = l + 1, ans += 'B'; } else if (l > 0 && dpl[i][j][k + 1][l - 1]) { nj = j, nk = k + 1, nl = l - 1, ans += 'C'; } } else { if (j > 0 && dpl[i][j - 1][k][l + 1]) { nj = j - 1, nk = k, nl = l + 1, ans += 'A'; } else if (l > 0 && dpl[i][j + 1][k][l - 1]) { nj = j + 1, nk = k, nl = l - 1, ans += 'C'; } } } cout << "Yes" << endl; reverse(all(ans)); rep(i, n) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) #define sz(v) ((int)v.size()) using namespace std; using i64 = long long; using f80 = long double; using vi32 = vector<int>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << endl; exit(0); } inline void no() { cout << "No" << endl; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { x = max(x, y); } template <typename T> inline void amin(T &x, T y) { x = min(x, y); } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } int dpl[100001][5][5][5]; void solve() { int n, a, b, c; cin >> n >> a >> b >> c; vstr s(n); cin >> s; amin(a, 2); amin(b, 2); amin(c, 2); dpl[0][a][b][c] = 1; rep(i, n) repc(j, 3) repc(k, 3) repc(l, 3) { if (dpl[i][j][k][l] == 0) continue; if (s[i] == "AB") { if (j > 0) dpl[i + 1][j - 1][k + 1][l] = 1; if (k > 0) dpl[i + 1][j + 1][k - 1][l] = 1; } else if (s[i] == "BC") { if (k > 0) dpl[i + 1][j][k - 1][l + 1] = 1; if (l > 0) dpl[i + 1][j][k + 1][l - 1] = 1; } else { if (j > 0) dpl[i + 1][j - 1][k][l + 1] = 1; if (l > 0) dpl[i + 1][j + 1][k][l - 1] = 1; } } bool ok = false; int nj, nk, nl; repc(j, 3) repc(k, 3) repc(l, 3) { if (!ok && dpl[n][j][k][l]) { ok = true; nj = j, nk = k, nl = l; } } if (!ok) { cout << "No" << endl; return; } string ans; while (sz(ans) < n) { int i = n - sz(ans) - 1; int j = nj, k = nk, l = nl; if (s[i] == "AB") { if (j > 0 && dpl[i][j - 1][k + 1][l]) { nj = j - 1, nk = k + 1, nl = l, ans += 'A'; } else if (k > 0 && dpl[i][j + 1][k - 1][l]) { nj = j + 1, nk = k - 1, nl = l, ans += 'B'; } } else if (s[i] == "BC") { if (k > 0 && dpl[i][j][k - 1][l + 1]) { nj = j, nk = k - 1, nl = l + 1, ans += 'B'; } else if (l > 0 && dpl[i][j][k + 1][l - 1]) { nj = j, nk = k + 1, nl = l - 1, ans += 'C'; } } else { if (j > 0 && dpl[i][j - 1][k][l + 1]) { nj = j - 1, nk = k, nl = l + 1, ans += 'A'; } else if (l > 0 && dpl[i][j + 1][k][l - 1]) { nj = j + 1, nk = k, nl = l - 1, ans += 'C'; } } } cout << "Yes" << endl; reverse(all(ans)); rep(i, n) { cout << ans[i] << endl; } }
replace
82
83
82
83
TLE
p02692
C++
Runtime Error
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> using u8t = std::uint64_t; using i8t = std::int64_t; #define F(I, N) for (i8t I = 0, I##_N = N; I < I##_N; I++) #define FR(I, N) for (i8t I = N; I--;) #define R(V) \ i8t V; \ std::cin >> V; #define RV(V, N) \ std::vector<i8t> V; \ F(_i, N) { R(_x) V.push_back(_x); } #define RL1(line) std::getline(std::cin, line); #define RL(line) \ std::string line; \ RL1(line) #define RM(V, L, C) \ std::vector<char> V; \ F(_i, L) { RL(_l) F(_j, C) V.push_back(_l[_j]); } #define P(X) std::cout << (X) << std::endl; int main() { R(N) R(A) R(B) R(C); RL(dummy); i8t t[3] = {A, B, C}; std::string lines[3]; std::vector<char> out; auto check = [&]() { for (int s = 0; s < 8; s++) { i8t t2[3] = {t[0], t[1], t[2]}; bool fail = false; for (int i = 0; i < 3; i++) { int a = lines[i][0] - 'A', b = lines[i][1] - 'A'; if (s >> i & 1) std::swap(a, b); t2[a]++; t2[b]--; if (t2[b] < 0) { fail = true; break; } } if (!fail) { out.push_back(lines[0][s & 1]); int a = lines[0][0] - 'A', b = lines[0][1] - 'A'; if (s & 1) std::swap(a, b); t[a]++; t[b]--; return true; } } return false; }; F(I, N) { RL1(lines[2]); if (I >= 2) { if (!check()) goto No; } lines[0] = lines[1]; lines[1] = lines[2]; } lines[2] = "AA"; if (!check()) goto No; lines[0] = lines[1]; lines[1] = lines[2]; lines[2] = "AA"; if (!check()) goto No; P("Yes"); for (char c : out) P(c); return 0; No: P("No"); return 0; }
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdint> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> using u8t = std::uint64_t; using i8t = std::int64_t; #define F(I, N) for (i8t I = 0, I##_N = N; I < I##_N; I++) #define FR(I, N) for (i8t I = N; I--;) #define R(V) \ i8t V; \ std::cin >> V; #define RV(V, N) \ std::vector<i8t> V; \ F(_i, N) { R(_x) V.push_back(_x); } #define RL1(line) std::getline(std::cin, line); #define RL(line) \ std::string line; \ RL1(line) #define RM(V, L, C) \ std::vector<char> V; \ F(_i, L) { RL(_l) F(_j, C) V.push_back(_l[_j]); } #define P(X) std::cout << (X) << std::endl; int main() { R(N) R(A) R(B) R(C); RL(dummy); i8t t[3] = {A, B, C}; std::string lines[3]; std::vector<char> out; auto check = [&]() { for (int s = 0; s < 8; s++) { i8t t2[3] = {t[0], t[1], t[2]}; bool fail = false; for (int i = 0; i < 3; i++) { int a = lines[i][0] - 'A', b = lines[i][1] - 'A'; if (s >> i & 1) std::swap(a, b); t2[a]++; t2[b]--; if (t2[b] < 0) { fail = true; break; } } if (!fail) { out.push_back(lines[0][s & 1]); int a = lines[0][0] - 'A', b = lines[0][1] - 'A'; if (s & 1) std::swap(a, b); t[a]++; t[b]--; return true; } } return false; }; F(I, N) { RL1(lines[2]); if (I >= 2) { if (!check()) goto No; } lines[0] = lines[1]; lines[1] = lines[2]; } lines[2] = "AA"; if (N >= 2 && !check()) goto No; lines[0] = lines[1]; lines[1] = lines[2]; lines[2] = "AA"; if (!check()) goto No; P("Yes"); for (char c : out) P(c); return 0; No: P("No"); return 0; }
replace
73
74
73
74
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); const int mod = 1e9 + 7; const int N = 2e5 + 5; const int inf = 1e16 + 2; int dp[N][3][3][3], n, A, B, C, check = 0; char ans[N][3][3][3]; string s[N]; int rec(int idx, int a, int b, int c) { if (a < 0 or b < 0 or c < 0) return 0; if (idx == n) { check = 1; return 1; } if (dp[idx][a][b][c] != -1) return dp[idx][a][b][c]; int res = 0; if (s[idx] == "AB") { if (rec(idx + 1, a + 1, b - 1, c)) ans[idx][a][b][c] = 'A', res = 1; else if (rec(idx + 1, a - 1, b + 1, c)) ans[idx][a][b][c] = 'B', res = 1; } else if (s[idx] == "AC") { if (rec(idx + 1, a + 1, b, c - 1)) ans[idx][a][b][c] = 'A', res = 1; else if (rec(idx + 1, a - 1, b, c + 1)) ans[idx][a][b][c] = 'C', res = 1; } else { if (rec(idx + 1, a, b - 1, c + 1)) ans[idx][a][b][c] = 'C', res = 1; else if (rec(idx + 1, a, b + 1, c - 1)) ans[idx][a][b][c] = 'B', res = 1; } dp[idx][a][b][c] = res; return res; } void solve(int z) { memset(dp, -1, sizeof dp); cin >> n >> A >> B >> C; for (int i = 0; i < n; i++) cin >> s[i]; rec(0, A, B, C); if (check == 0) cout << "No"; else { cout << "Yes" << '\n'; int i = 0; while (n--) { cout << ans[i][A][B][C] << '\n'; if (ans[i][A][B][C] == 'A') { A++; if (s[i] == "AB") B--; else C--; } if (ans[i][A][B][C] == 'B') { B++; if (s[i] == "AB") A--; else C--; } if (ans[i][A][B][C] == 'C') { C++; if (s[i] == "AC") A--; else B--; } i++; } } } /* */ int32_t main() { fastio int testcase = 1; // cin >> testcase; int x = 1; while (testcase--) { solve(x++); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); const int mod = 1e9 + 7; const int N = 2e5 + 5; const int inf = 1e16 + 2; int dp[N][3][3][3], n, A, B, C, check = 0; char ans[N][3][3][3]; string s[N]; int rec(int idx, int a, int b, int c) { if (a < 0 or b < 0 or c < 0) return 0; if (idx == n) { check = 1; return 1; } if (dp[idx][a][b][c] != -1) return dp[idx][a][b][c]; int res = 0; if (s[idx] == "AB") { if (rec(idx + 1, a + 1, b - 1, c)) ans[idx][a][b][c] = 'A', res = 1; else if (rec(idx + 1, a - 1, b + 1, c)) ans[idx][a][b][c] = 'B', res = 1; } else if (s[idx] == "AC") { if (rec(idx + 1, a + 1, b, c - 1)) ans[idx][a][b][c] = 'A', res = 1; else if (rec(idx + 1, a - 1, b, c + 1)) ans[idx][a][b][c] = 'C', res = 1; } else { if (rec(idx + 1, a, b - 1, c + 1)) ans[idx][a][b][c] = 'C', res = 1; else if (rec(idx + 1, a, b + 1, c - 1)) ans[idx][a][b][c] = 'B', res = 1; } dp[idx][a][b][c] = res; return res; } void solve(int z) { memset(dp, -1, sizeof dp); cin >> n >> A >> B >> C; for (int i = 0; i < n; i++) cin >> s[i]; A = min(2LL, A); B = min(2LL, B); C = min(2LL, C); rec(0, A, B, C); if (check == 0) cout << "No"; else { cout << "Yes" << '\n'; int i = 0; while (n--) { cout << ans[i][A][B][C] << '\n'; if (ans[i][A][B][C] == 'A') { A++; if (s[i] == "AB") B--; else C--; } if (ans[i][A][B][C] == 'B') { B++; if (s[i] == "AB") A--; else C--; } if (ans[i][A][B][C] == 'C') { C++; if (s[i] == "AC") A--; else B--; } i++; } } } /* */ int32_t main() { fastio int testcase = 1; // cin >> testcase; int x = 1; while (testcase--) { solve(x++); } return 0; }
insert
52
52
52
55
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using tll = tuple<ll, ll>; using tlll = tuple<ll, ll, ll>; using vs = vector<string>; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define rep(i, n) range(i, 0, n) #define rrep(i, n) for (ll i = ((ll)n) - 1; i >= 0; i--) #define range(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++) #define LINF ((ll)1ll << 60) #define INF ((int)1 << 30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout << setprecision(a) << fixed #define fs first #define sc second #define PI (3.1415926535897932384) int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } int sgn(const double &r) { return (r > EPS) - (r < -EPS); } // a>0 : sgn(a)>0 int sgn(const double &a, const double &b) { return sgn(a - b); } // b<=c : sgn(b,c)<=0 template <class T> void puta(T &&t) { cout << t << "\n"; } template <class H, class... T> void puta(H &&h, T &&...t) { cout << h << ' '; puta(t...); } template <class S, class T> void tf(bool b, S t, T f) { if (b) puta(t); else puta(f); } void YN(bool b) { tf(b, "YES", "NO"); } void Yn(bool b) { tf(b, "Yes", "No"); } void yn(bool b) { tf(b, "yes", "no"); } template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "[" << p.first << ", " << p.second << "]"; return os; }; template <class S> auto &operator<<(ostream &os, vector<S> t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; } template <class S> auto &operator>>(istream &is, vector<S> &t) { for (S &a : t) cin >> a; return is; } /*他のライブラリを入れる場所*/ int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, a, b, c; cin >> n >> a >> b >> c; vs s(n); cin >> s; if (a + b + c == 0) { puta("No"); return 0; } vl v{a, b, c}; vector<char> ans; vs other{"BC", "AC", "AB"}; rep(i, n) { ll x = s[i][0] - 'A'; ll y = s[i][1] - 'A'; if (/*!v[0] + !v[1] + !v[2] == 2 and */ v[x] == 0 and v[y] == 0) { puta("No"); return 0; } else { if (v[x] <= v[y]) { if (v[y] == 1) { if (i + 1 != n and s[i + 1] == other[x]) { v[x]--; v[y]++; ans.push_back((char)('A' + y)); } } else { v[x]++; v[y]--; ans.push_back((char)('A' + x)); } } else { v[x]--; v[y]++; ans.push_back((char)('A' + y)); } } } puta("Yes"); rep(i, n) puta(ans[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; using tll = tuple<ll, ll>; using tlll = tuple<ll, ll, ll>; using vs = vector<string>; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define rep(i, n) range(i, 0, n) #define rrep(i, n) for (ll i = ((ll)n) - 1; i >= 0; i--) #define range(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++) #define LINF ((ll)1ll << 60) #define INF ((int)1 << 30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout << setprecision(a) << fixed #define fs first #define sc second #define PI (3.1415926535897932384) int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } int sgn(const double &r) { return (r > EPS) - (r < -EPS); } // a>0 : sgn(a)>0 int sgn(const double &a, const double &b) { return sgn(a - b); } // b<=c : sgn(b,c)<=0 template <class T> void puta(T &&t) { cout << t << "\n"; } template <class H, class... T> void puta(H &&h, T &&...t) { cout << h << ' '; puta(t...); } template <class S, class T> void tf(bool b, S t, T f) { if (b) puta(t); else puta(f); } void YN(bool b) { tf(b, "YES", "NO"); } void Yn(bool b) { tf(b, "Yes", "No"); } void yn(bool b) { tf(b, "yes", "no"); } template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) { os << "[" << p.first << ", " << p.second << "]"; return os; }; template <class S> auto &operator<<(ostream &os, vector<S> t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; } template <class S> auto &operator>>(istream &is, vector<S> &t) { for (S &a : t) cin >> a; return is; } /*他のライブラリを入れる場所*/ int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, a, b, c; cin >> n >> a >> b >> c; vs s(n); cin >> s; if (a + b + c == 0) { puta("No"); return 0; } vl v{a, b, c}; vector<char> ans; vs other{"BC", "AC", "AB"}; rep(i, n) { ll x = s[i][0] - 'A'; ll y = s[i][1] - 'A'; if (/*!v[0] + !v[1] + !v[2] == 2 and */ v[x] == 0 and v[y] == 0) { puta("No"); return 0; } else { if (v[x] <= v[y]) { if (v[x] == 1 and v[y] == 1 and i + 1 != n and s[i + 1] == other[x]) { v[x]--; v[y]++; ans.push_back((char)('A' + y)); } else { v[x]++; v[y]--; ans.push_back((char)('A' + x)); } } else { v[x]--; v[y]++; ans.push_back((char)('A' + y)); } } } puta("Yes"); rep(i, n) puta(ans[i]); return 0; }
replace
111
117
111
115
0
p02692
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; namespace utils { #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) template <class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>; template <class T> using min_queue = p_queue<T, greater<T>>; template <class T> using max_queue = p_queue<T, less<T>>; template <class T> inline bool UPMIN(T &X, const T &A) { if (X > A) { X = A; return true; } return false; } template <class T> inline bool UPMAX(T &X, const T &A) { if (X < A) { X = A; return true; } return false; } template <class T> vector<T> VEC(int n, T t) { return vector<T>(n, t); } template <class... Ts> auto VEC(int n, Ts... ts) { return vector<decltype(VEC(ts...))>(n, VEC(ts...)); } template <class S, class T> istream &operator>>(istream &is, tuple<S, T> &t) { return is >> get<0>(t) >> get<1>(t); } template <class S, class T, class U> istream &operator>>(istream &is, tuple<S, T, U> &t) { return is >> get<0>(t) >> get<1>(t) >> get<2>(t); } template <class S, class T> ostream &operator<<(ostream &os, const tuple<S, T> &t) { return os << get<0>(t) << ' ' << get<1>(t); } template <class S, class T, class U> ostream &operator<<(ostream &os, const tuple<S, T, U> &t) { return os << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t); } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) { is >> x; } return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << ' ' << *p++; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << '\n' << *p++; } return os; } template <class... Ts> ostream &operator<<(ostream &os, const vector<tuple<Ts...>> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << '\n' << *p++; } return os; } constexpr long long INFLL = 1'000'000'000'000'000'000ll; constexpr int INF = 1'000'000'000; constexpr double PI = 3.14'159'265'358'973; constexpr double EPS = 1e-10; } // namespace utils using namespace utils; class solver { istream &is; ostream &os; public: solver(istream &I, ostream &O) : is(I), os(O) {} int N; vector<int> ABC; vector<pair<int, int>> S; bool input() { ABC.resize(3); is >> N >> ABC; S.resize(N); for (int i = 0; i < N; ++i) { char s1, s2; is >> s1 >> s2; S[i] = {s1 - 'A', s2 - 'A'}; } // end i return !!is; } string greed(int k) { stringstream ans; for (int i = k; i < N; ++i) { int x, y; tie(x, y) = S[i]; if (ABC[x] < ABC[y]) { ans << char(x + 'A') << '\n'; ABC[x]++; ABC[y]--; } else if (ABC[x] == 0) { return "No\n"; } else { ans << char(y + 'A') << '\n'; ABC[x]--; ABC[y]++; } } // end i cout << "Yes\n"; return ans.str(); } string dfs(int i) { if (ABC[0] < 0 or ABC[1] < 0 or ABC[2] < 0) { assert(false); } if (i == N) { return ""; } int x, y; tie(x, y) = S[i]; if (ABC[x] > 0) { ABC[x]--; ABC[y]++; string f = dfs(i + 1); if (f[0] != '-') { return f + char('A' + y); } ABC[x]++; ABC[y]--; } if (ABC[y] > 0) { ABC[y]--; ABC[x]++; string f = dfs(i + 1); if (f[0] != '-') { return f + char('A' + x); } ABC[x]++; ABC[y]--; } return "-"; } void run(); }; int main(int argc, char *argv[]) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(16) << scientific; #ifdef XELMH string test_cases = "test_F.txt"; cerr << test_cases << " -->" << endl; auto fs = fstream(test_cases, fstream::in); int loop = 0; while (fs) { loop++; cout << '#' << loop << "#------\n"; solver(fs, cout).run(); } if (loop <= 1) { cout << "===" << endl; while (cin) solver(cin, cout).run(); } #else solver(cin, cout).run(); #endif return 0; } void solver::run() { if (!input()) return; ll sum = min(ABC[0], 3) + min(ABC[1], 3) + ABC[2]; if (sum > 2) { os << greed(0); return; } // assert(false); // cout << "No\n"; string ans = dfs(0); if (ans.empty() or ans[0] == '-') { os << "No\n"; } else { os << "Yes\n"; for (int k = ans.size() - 1; k >= 0; --k) { cout << ans[k] << endl; } // end k } }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; namespace utils { #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) template <class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>; template <class T> using min_queue = p_queue<T, greater<T>>; template <class T> using max_queue = p_queue<T, less<T>>; template <class T> inline bool UPMIN(T &X, const T &A) { if (X > A) { X = A; return true; } return false; } template <class T> inline bool UPMAX(T &X, const T &A) { if (X < A) { X = A; return true; } return false; } template <class T> vector<T> VEC(int n, T t) { return vector<T>(n, t); } template <class... Ts> auto VEC(int n, Ts... ts) { return vector<decltype(VEC(ts...))>(n, VEC(ts...)); } template <class S, class T> istream &operator>>(istream &is, tuple<S, T> &t) { return is >> get<0>(t) >> get<1>(t); } template <class S, class T, class U> istream &operator>>(istream &is, tuple<S, T, U> &t) { return is >> get<0>(t) >> get<1>(t) >> get<2>(t); } template <class S, class T> ostream &operator<<(ostream &os, const tuple<S, T> &t) { return os << get<0>(t) << ' ' << get<1>(t); } template <class S, class T, class U> ostream &operator<<(ostream &os, const tuple<S, T, U> &t) { return os << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t); } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) { is >> x; } return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << ' ' << *p++; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << '\n' << *p++; } return os; } template <class... Ts> ostream &operator<<(ostream &os, const vector<tuple<Ts...>> &v) { auto p = v.begin(); assert(p != v.end()); os << *p++; while (p != v.end()) { os << '\n' << *p++; } return os; } constexpr long long INFLL = 1'000'000'000'000'000'000ll; constexpr int INF = 1'000'000'000; constexpr double PI = 3.14'159'265'358'973; constexpr double EPS = 1e-10; } // namespace utils using namespace utils; class solver { istream &is; ostream &os; public: solver(istream &I, ostream &O) : is(I), os(O) {} int N; vector<int> ABC; vector<pair<int, int>> S; bool input() { ABC.resize(3); is >> N >> ABC; S.resize(N); for (int i = 0; i < N; ++i) { char s1, s2; is >> s1 >> s2; S[i] = {s1 - 'A', s2 - 'A'}; } // end i return !!is; } string greed(int k) { stringstream ans; for (int i = k; i < N; ++i) { int x, y; tie(x, y) = S[i]; if (ABC[x] < ABC[y]) { ans << char(x + 'A') << '\n'; ABC[x]++; ABC[y]--; } else if (ABC[x] == 0) { return "No\n"; } else { ans << char(y + 'A') << '\n'; ABC[x]--; ABC[y]++; } } // end i cout << "Yes\n"; return ans.str(); } string dfs(int i) { if (ABC[0] < 0 or ABC[1] < 0 or ABC[2] < 0) { return "-"; } if (i == N) { return ""; } int x, y; tie(x, y) = S[i]; if (ABC[x] > 0) { ABC[x]--; ABC[y]++; string f = dfs(i + 1); if (f[0] != '-') { return f + char('A' + y); } ABC[x]++; ABC[y]--; } if (ABC[y] > 0) { ABC[y]--; ABC[x]++; string f = dfs(i + 1); if (f[0] != '-') { return f + char('A' + x); } ABC[x]++; ABC[y]--; } return "-"; } void run(); }; int main(int argc, char *argv[]) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(16) << scientific; #ifdef XELMH string test_cases = "test_F.txt"; cerr << test_cases << " -->" << endl; auto fs = fstream(test_cases, fstream::in); int loop = 0; while (fs) { loop++; cout << '#' << loop << "#------\n"; solver(fs, cout).run(); } if (loop <= 1) { cout << "===" << endl; while (cin) solver(cin, cout).run(); } #else solver(cin, cout).run(); #endif return 0; } void solver::run() { if (!input()) return; ll sum = min(ABC[0], 3) + min(ABC[1], 3) + ABC[2]; if (sum > 2) { os << greed(0); return; } // assert(false); // cout << "No\n"; string ans = dfs(0); if (ans.empty() or ans[0] == '-') { os << "No\n"; } else { os << "Yes\n"; for (int k = ans.size() - 1; k >= 0; --k) { cout << ans[k] << endl; } // end k } }
replace
168
169
168
169
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<char> ans; bool ok = true; if (A + B + C >= 3) { for (int i = 0; i < N; i++) { string s; cin >> s; if (s == "AB") { if (A > B) { ans.push_back('B'); B++; A--; } else { ans.push_back('A'); A++; B--; } } else if (s == "AC") { if (A > C) { ans.push_back('C'); C++; A--; } else { ans.push_back('A'); A++; C--; } } else { if (B > C) { ans.push_back('C'); C++; B--; } else { ans.push_back('B'); B++; C--; } } if (A < 0 || B < 0 || C < 0) { ok = false; break; } } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) cout << ans[i] << endl; } else { cout << "No" << endl; } } else { vector<string> s(N); for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) { if (s[i] == "AB") { if (A > B) { ans.push_back('B'); B++; A--; } else { if (A == B && A == 1 && i + 1 < s.size() && s[i + 1] != "AB") { if (s[i + 1] == "AC") { ans.push_back('A'); A++; B--; } else { ans.push_back('B'); B++; A--; } } else { ans.push_back('A'); A++; B--; } } } else if (s[i] == "AC") { if (A > C) { ans.push_back('C'); C++; A--; } else { if (A == C && A == 1 && i + 1 < s.size() && s[i + 1] != "AC") { if (s[i + 1] == "AB") { ans.push_back('A'); A++; C--; } else { ans.push_back('C'); C++; A--; } } else { ans.push_back('A'); A++; C--; } } } else { if (B > C) { ans.push_back('C'); C++; B--; } else { if (C == B && C == 1 && i + 1 < s.size() && s[i + 1] != "BC") { if (s[i + 1] == "AB") { ans.push_back('B'); B++; C--; } else { ans.push_back('C'); C++; B--; } } else { ans.push_back('B'); B++; C--; } } } if (A < 0 || B < 0 || C < 0) { ok = false; break; } } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) cout << ans[i] << endl; } else { cout << "No" << endl; for (int i = 0; i < s.size(); i++) cout << ans[i] << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<char> ans; bool ok = true; if (A + B + C >= 3) { for (int i = 0; i < N; i++) { string s; cin >> s; if (s == "AB") { if (A > B) { ans.push_back('B'); B++; A--; } else { ans.push_back('A'); A++; B--; } } else if (s == "AC") { if (A > C) { ans.push_back('C'); C++; A--; } else { ans.push_back('A'); A++; C--; } } else { if (B > C) { ans.push_back('C'); C++; B--; } else { ans.push_back('B'); B++; C--; } } if (A < 0 || B < 0 || C < 0) { ok = false; break; } } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) cout << ans[i] << endl; } else { cout << "No" << endl; } } else { vector<string> s(N); for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) { if (s[i] == "AB") { if (A > B) { ans.push_back('B'); B++; A--; } else { if (A == B && A == 1 && i + 1 < s.size() && s[i + 1] != "AB") { if (s[i + 1] == "AC") { ans.push_back('A'); A++; B--; } else { ans.push_back('B'); B++; A--; } } else { ans.push_back('A'); A++; B--; } } } else if (s[i] == "AC") { if (A > C) { ans.push_back('C'); C++; A--; } else { if (A == C && A == 1 && i + 1 < s.size() && s[i + 1] != "AC") { if (s[i + 1] == "AB") { ans.push_back('A'); A++; C--; } else { ans.push_back('C'); C++; A--; } } else { ans.push_back('A'); A++; C--; } } } else { if (B > C) { ans.push_back('C'); C++; B--; } else { if (C == B && C == 1 && i + 1 < s.size() && s[i + 1] != "BC") { if (s[i + 1] == "AB") { ans.push_back('B'); B++; C--; } else { ans.push_back('C'); C++; B--; } } else { ans.push_back('B'); B++; C--; } } } if (A < 0 || B < 0 || C < 0) { ok = false; break; } } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) cout << ans[i] << endl; } else { cout << "No" << endl; } } }
delete
138
140
138
138
0
p02692
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; } if (A + B + C >= 3) { string seq; bool ok = true; for (int i = 0; i < N; ++i) { if (S[i] == "AB") { if (A >= B) { --A; ++B; seq += "B"; } else { --B; ++A; seq += "A"; } if (A < 0 || B < 0) { ok = false; break; } } if (S[i] == "BC") { if (B >= C) { --B; ++C; seq += "C"; } else { --C; ++B; seq += "B"; } if (B < 0 || C < 0) { ok = false; break; } } if (S[i] == "AC") { if (C >= A) { --C; ++A; seq += "A"; } else { --A; ++C; seq += "C"; } if (C < 0 || A < 0) { ok = false; break; } } } if (ok) { cout << "Yes" << '\n'; for (int i = 0; i < N; ++i) { cout << seq[i] << '\n'; } } else { cout << "No" << '\n'; } } else { vector<map<vector<int>, vector<int>>> dp(N + 1); dp[0][{A, B, C}] = {-1, -1, -1}; for (int i = 0; i < N; ++i) { map<vector<int>, vector<int>>::iterator it = dp[i].begin(); while (it != dp[i].end()) { vector<int> v = it->first; for (int j = 0; j < 3; ++j) { if (j == 0 && S[i] != "AB") continue; if (j == 1 && S[i] != "BC") continue; if (j == 2 && S[i] != "AC") continue; if (v[j] >= 1) { vector<int> w = v; --w[j]; ++w[(j + 1) % 3]; dp[i + 1][w] = v; } if (v[(j + 1) % 3] >= 1) { vector<int> w = v; --w[(j + 1) % 3]; ++w[j]; dp[i + 1][w] = v; } } ++it; } } if (dp[N].empty()) { cout << "No" << endl; } else { vector<int> p = dp[N].begin()->first; string seq; for (int i = N - 1; i >= 0; --i) { vector<int> np = dp[N][p]; for (int j = 0; j < 3; ++j) { if (np[j] < p[j]) { seq += char('A' + j); } } p = np; } reverse(seq.begin(), seq.end()); cout << "Yes" << '\n'; for (int i = 0; i < N; ++i) { cout << seq[i] << '\n'; } } } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; } if (A + B + C >= 3) { string seq; bool ok = true; for (int i = 0; i < N; ++i) { if (S[i] == "AB") { if (A >= B) { --A; ++B; seq += "B"; } else { --B; ++A; seq += "A"; } if (A < 0 || B < 0) { ok = false; break; } } if (S[i] == "BC") { if (B >= C) { --B; ++C; seq += "C"; } else { --C; ++B; seq += "B"; } if (B < 0 || C < 0) { ok = false; break; } } if (S[i] == "AC") { if (C >= A) { --C; ++A; seq += "A"; } else { --A; ++C; seq += "C"; } if (C < 0 || A < 0) { ok = false; break; } } } if (ok) { cout << "Yes" << '\n'; for (int i = 0; i < N; ++i) { cout << seq[i] << '\n'; } } else { cout << "No" << '\n'; } } else { vector<map<vector<int>, vector<int>>> dp(N + 1); dp[0][{A, B, C}] = {-1, -1, -1}; for (int i = 0; i < N; ++i) { map<vector<int>, vector<int>>::iterator it = dp[i].begin(); while (it != dp[i].end()) { vector<int> v = it->first; for (int j = 0; j < 3; ++j) { if (j == 0 && S[i] != "AB") continue; if (j == 1 && S[i] != "BC") continue; if (j == 2 && S[i] != "AC") continue; if (v[j] >= 1) { vector<int> w = v; --w[j]; ++w[(j + 1) % 3]; dp[i + 1][w] = v; } if (v[(j + 1) % 3] >= 1) { vector<int> w = v; --w[(j + 1) % 3]; ++w[j]; dp[i + 1][w] = v; } } ++it; } } if (dp[N].empty()) { cout << "No" << endl; } else { vector<int> p = dp[N].begin()->first; string seq; for (int i = N - 1; i >= 0; --i) { vector<int> np = dp[i + 1][p]; for (int j = 0; j < 3; ++j) { if (np[j] < p[j]) { seq += char('A' + j); } } p = np; } reverse(seq.begin(), seq.end()); cout << "Yes" << '\n'; for (int i = 0; i < N; ++i) { cout << seq[i] << '\n'; } } } return 0; }
replace
108
109
108
109
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include "string" // #define int long long #define pi pair<int, int> #define ff first #define ss second #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr) const int N = 1e5 + 1; int n, a, b, c; vector<string> s; int dp[N][4][4][4]; int go(int id, int a, int b, int c) { if (a < 0 or b < 0 or c < 0) return 0; a = min(a, 3); b = min(b, 3); c = min(c, 3); if (id >= n) { dp[id][a][b][c] = 1; return 1; } int &tmp = dp[id][a][b][c]; if (tmp != -1) return tmp; tmp = 0; if (s[id] == "AB") { tmp |= go(id + 1, a + 1, b - 1, c); tmp |= go(id + 1, a - 1, b + 1, c); } else if (s[id] == "AC") { tmp |= go(id + 1, a + 1, b, c - 1); tmp |= go(id + 1, a - 1, b, c + 1); } else { tmp |= go(id + 1, a, b + 1, c - 1); tmp |= go(id + 1, a, b - 1, c + 1); } return tmp; } void trace(int id, int a, int b, int c) { if (id >= n) return; if (s[id] == "AB") { if (a < 3 && b > 0 && dp[id + 1][a + 1][b - 1][c] == 1) { cout << 'A' << endl; trace(id + 1, a + 1, b - 1, c); } else { cout << 'B' << endl; trace(id + 1, a - 1, b + 1, c); } } else if (s[id] == "AC") { if (a < 3 && c > 0 && dp[id + 1][a + 1][b][c - 1] == 1) { cout << 'A' << endl; trace(id + 1, a + 1, b, c - 1); } else { cout << 'C' << endl; trace(id + 1, a - 1, b, c + 1); } } else { if (b < 3 && c > 0 && dp[id + 1][a][b + 1][c - 1] == 1) { cout << 'B' << endl; trace(id + 1, a, b + 1, c - 1); } else { cout << 'C' << endl; trace(id + 1, a, b - 1, c + 1); } } } int32_t main() { boost; cin >> n >> a >> b >> c; s.resize(n); for (int i = 0; i < n; i++) cin >> s[i]; memset(dp, -1, sizeof dp); if (go(0, a, b, c)) { cout << "Yes" << endl; trace(0, a, b, c); } else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #include "string" // #define int long long #define pi pair<int, int> #define ff first #define ss second #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr) const int N = 1e5 + 1; int n, a, b, c; vector<string> s; int dp[N][4][4][4]; int go(int id, int a, int b, int c) { if (a < 0 or b < 0 or c < 0) return 0; a = min(a, 3); b = min(b, 3); c = min(c, 3); if (id >= n) { dp[id][a][b][c] = 1; return 1; } int &tmp = dp[id][a][b][c]; if (tmp != -1) return tmp; tmp = 0; if (s[id] == "AB") { tmp |= go(id + 1, a + 1, b - 1, c); tmp |= go(id + 1, a - 1, b + 1, c); } else if (s[id] == "AC") { tmp |= go(id + 1, a + 1, b, c - 1); tmp |= go(id + 1, a - 1, b, c + 1); } else { tmp |= go(id + 1, a, b + 1, c - 1); tmp |= go(id + 1, a, b - 1, c + 1); } return tmp; } void trace(int id, int a, int b, int c) { if (id >= n) return; a = min(a, 3); b = min(b, 3); c = min(c, 3); if (s[id] == "AB") { if (a < 3 && b > 0 && dp[id + 1][a + 1][b - 1][c] == 1) { cout << 'A' << endl; trace(id + 1, a + 1, b - 1, c); } else { cout << 'B' << endl; trace(id + 1, a - 1, b + 1, c); } } else if (s[id] == "AC") { if (a < 3 && c > 0 && dp[id + 1][a + 1][b][c - 1] == 1) { cout << 'A' << endl; trace(id + 1, a + 1, b, c - 1); } else { cout << 'C' << endl; trace(id + 1, a - 1, b, c + 1); } } else { if (b < 3 && c > 0 && dp[id + 1][a][b + 1][c - 1] == 1) { cout << 'B' << endl; trace(id + 1, a, b + 1, c - 1); } else { cout << 'C' << endl; trace(id + 1, a, b - 1, c + 1); } } } int32_t main() { boost; cin >> n >> a >> b >> c; s.resize(n); for (int i = 0; i < n; i++) cin >> s[i]; memset(dp, -1, sizeof dp); if (go(0, a, b, c)) { cout << "Yes" << endl; trace(0, a, b, c); } else cout << "No" << endl; }
insert
46
46
46
49
0
p02692
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-12) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<VE>; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, a, b, c; cin >> n >> a >> b >> c; if (a + b + c == 0) { cout << "No" << endl; return 0; } vector<string> s(n); rep(i, n) cin >> s[i]; if (a + b + c == 1) { vector<char> ans; rep(i, n) { if (s[i] == "AB") { if (a == 0 && b == 0) { cout << "No" << endl; return 0; } if (a == 1) { ans[i] = 'B'; a--; b++; } else { ans[i] = 'A'; a++; b--; } } else if (s[i] == "BC") { if (b == 0 && c == 0) { cout << "No" << endl; return 0; } if (b == 1) { ans[i] = 'C'; b--; c++; } else { ans[i] = 'B'; b++; c--; } } else { if (a == 0 && c == 0) { cout << "No" << endl; return 0; } if (a == 1) { ans[i] = 'C'; a--; c++; } else { ans[i] = 'A'; a++; c--; } } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; } if (s[0] == "AB") { if (a == 0 && b == 0) { cout << "No" << endl; return 0; } } else if (s[0] == "BC") { if (b == 0 && c == 0) { cout << "No" << endl; return 0; } } else { if (a == 0 && c == 0) { cout << "No" << endl; return 0; } } vector<char> ans(n); rep(i, n) { if (s[i] == "AB") { if (a == 0 && b > 0) { ans[i] = 'A'; a++; b--; } else if (a > 0 && b == 0) { ans[i] = 'B'; a--; b++; } else { if (a + b + c == 2 && a == 1 && b == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "BC") { ans[i] = 'B'; a--; b++; } else { ans[i] = 'A'; a++; b--; } } else { if (a < b) { ans[i] = 'A'; a++; b--; } else { ans[i] = 'B'; a--; b++; } } } } else if (s[i] == "BC") { if (b == 0 && c > 0) { ans[i] = 'B'; b++; c--; } else if (b > 0 && c == 0) { ans[i] = 'C'; b--; c++; } else { if (a + b + c == 2 && b == 1 && c == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "AB") { ans[i] = 'B'; b++; c--; } else { ans[i] = 'C'; b--; c++; } } else { if (b < c) { ans[i] = 'B'; b++; c--; } else { ans[i] = 'C'; b--; c++; } } } } else { if (a == 0 && c > 0) { ans[i] = 'A'; a++; c--; } else if (a > 0 && c == 0) { ans[i] = 'C'; a--; c++; } else { if (a + b + c == 2 && a == 1 && c == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "AB") { ans[i] = 'A'; a++; c--; } else { ans[i] = 'C'; a--; c++; } } else { if (a < c) { ans[i] = 'A'; a++; c--; } else { ans[i] = 'C'; a--; c++; } } } } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-12) #define pb push_back long long MOD = 1000000007; // const long long MOD = 998244353; const long long INF = 1LL << 60; const double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<VE>; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, a, b, c; cin >> n >> a >> b >> c; if (a + b + c == 0) { cout << "No" << endl; return 0; } vector<string> s(n); rep(i, n) cin >> s[i]; if (a + b + c == 1) { vector<char> ans(n); rep(i, n) { if (s[i] == "AB") { if (a == 0 && b == 0) { cout << "No" << endl; return 0; } if (a == 1) { ans[i] = 'B'; a--; b++; } else { ans[i] = 'A'; a++; b--; } } else if (s[i] == "BC") { if (b == 0 && c == 0) { cout << "No" << endl; return 0; } if (b == 1) { ans[i] = 'C'; b--; c++; } else { ans[i] = 'B'; b++; c--; } } else { if (a == 0 && c == 0) { cout << "No" << endl; return 0; } if (a == 1) { ans[i] = 'C'; a--; c++; } else { ans[i] = 'A'; a++; c--; } } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; } if (s[0] == "AB") { if (a == 0 && b == 0) { cout << "No" << endl; return 0; } } else if (s[0] == "BC") { if (b == 0 && c == 0) { cout << "No" << endl; return 0; } } else { if (a == 0 && c == 0) { cout << "No" << endl; return 0; } } vector<char> ans(n); rep(i, n) { if (s[i] == "AB") { if (a == 0 && b > 0) { ans[i] = 'A'; a++; b--; } else if (a > 0 && b == 0) { ans[i] = 'B'; a--; b++; } else { if (a + b + c == 2 && a == 1 && b == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "BC") { ans[i] = 'B'; a--; b++; } else { ans[i] = 'A'; a++; b--; } } else { if (a < b) { ans[i] = 'A'; a++; b--; } else { ans[i] = 'B'; a--; b++; } } } } else if (s[i] == "BC") { if (b == 0 && c > 0) { ans[i] = 'B'; b++; c--; } else if (b > 0 && c == 0) { ans[i] = 'C'; b--; c++; } else { if (a + b + c == 2 && b == 1 && c == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "AB") { ans[i] = 'B'; b++; c--; } else { ans[i] = 'C'; b--; c++; } } else { if (b < c) { ans[i] = 'B'; b++; c--; } else { ans[i] = 'C'; b--; c++; } } } } else { if (a == 0 && c > 0) { ans[i] = 'A'; a++; c--; } else if (a > 0 && c == 0) { ans[i] = 'C'; a--; c++; } else { if (a + b + c == 2 && a == 1 && c == 1 && i != n - 1 && s[i] != s[i + 1]) { if (s[i + 1] == "AB") { ans[i] = 'A'; a++; c--; } else { ans[i] = 'C'; a--; c++; } } else { if (a < c) { ans[i] = 'A'; a++; c--; } else { ans[i] = 'C'; a--; c++; } } } } } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; }
replace
259
260
259
260
0
p02692
C++
Runtime Error
/*#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long // comment it out when MLE // # define endl "\n" #define gok \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // # define m 163577857 // # define MOD 163577857 #define pi acos(-1) #define fi first #define se second #define REP(i, n) for (int i = 1; i <= n; i++) const ll mod = 1000000007; const int K = 2; // typedef vector<vector<int> > matrix; int add(int a, int b, int mod) { a %= mod; b %= mod; a += b; if (a >= mod) a -= mod; if (a < 0) { a += mod; a %= mod; } return a; } int mul(ll a, int b, int mod) { a %= mod; b %= mod; a *= b; return a % mod; } int po(int a, int b, int mod) { if (b == 0) return 1; if (b % 2 == 0) return po(mul(a, a, mod), b / 2, mod); return mul(a, po(mul(a, a, mod), (b - 1) / 2, mod), mod); } ll fact[1000003]; ll inv[1000003]; void fact0() { int i, j; fact[0] = 1; for (i = 1; i <= 200000; i++) { fact[i] = i * fact[i - 1] % mod; } inv[0] = 1; inv[1] = 1; ll p = mod; for (i = 2; i <= 200000; i++) inv[i] = (p - (p / i) * inv[p % i] % p) % p; for (i = 2; i <= 200000; i++) { inv[i] *= inv[i - 1]; inv[i] %= mod; } } set<int> v[100005]; signed main() { gok // fact0(); int n, a, b, c; cin >> n >> a >> b >> c; map<string, int> mp; map<char, int> mp1; mp1['A'] = a; mp1['B'] = b; mp1['C'] = c; mp["AC"] = 0; mp["AB"] = 0; mp["BC"] = 0; vector<char> vv; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; // mp[s]++; } bool ch = true; for (int i = 0; i < n; i++) { if (mp1[s[i][0]] > mp1[s[i][1]]) { mp1[s[i][0]]--; mp1[s[i][1]]++; vv.push_back(s[i][1]); } else if (mp1[s[i][0]] < mp1[s[i][1]]) { mp1[s[i][0]]++; mp1[s[i][1]]--; vv.push_back(s[i][0]); } else if (mp1[s[i][0]] == mp1[s[i][1]]) { if (mp1[s[i][0]] == 0) { ch = false; break; } if (s[i][0] == s[i + 1][1] || s[i][0] == s[i + 1][0]) { vv.push_back(s[i][0]); mp1[s[i][0]]++; mp1[s[i][1]]--; } else { vv.push_back(s[i][1]); mp1[s[i][0]]--; mp1[s[i][1]]++; } } } if (!ch) cout << "No"; else { cout << "Yes" << endl; for (int i = 0; i < vv.size(); i++) cout << vv[i] << endl; } return 0; }
/*#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long // comment it out when MLE // # define endl "\n" #define gok \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // # define m 163577857 // # define MOD 163577857 #define pi acos(-1) #define fi first #define se second #define REP(i, n) for (int i = 1; i <= n; i++) const ll mod = 1000000007; const int K = 2; // typedef vector<vector<int> > matrix; int add(int a, int b, int mod) { a %= mod; b %= mod; a += b; if (a >= mod) a -= mod; if (a < 0) { a += mod; a %= mod; } return a; } int mul(ll a, int b, int mod) { a %= mod; b %= mod; a *= b; return a % mod; } int po(int a, int b, int mod) { if (b == 0) return 1; if (b % 2 == 0) return po(mul(a, a, mod), b / 2, mod); return mul(a, po(mul(a, a, mod), (b - 1) / 2, mod), mod); } ll fact[1000003]; ll inv[1000003]; void fact0() { int i, j; fact[0] = 1; for (i = 1; i <= 200000; i++) { fact[i] = i * fact[i - 1] % mod; } inv[0] = 1; inv[1] = 1; ll p = mod; for (i = 2; i <= 200000; i++) inv[i] = (p - (p / i) * inv[p % i] % p) % p; for (i = 2; i <= 200000; i++) { inv[i] *= inv[i - 1]; inv[i] %= mod; } } set<int> v[100005]; signed main() { gok // fact0(); int n, a, b, c; cin >> n >> a >> b >> c; map<string, int> mp; map<char, int> mp1; mp1['A'] = a; mp1['B'] = b; mp1['C'] = c; mp["AC"] = 0; mp["AB"] = 0; mp["BC"] = 0; vector<char> vv; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; // mp[s]++; } bool ch = true; for (int i = 0; i < n; i++) { if (mp1[s[i][0]] > mp1[s[i][1]]) { mp1[s[i][0]]--; mp1[s[i][1]]++; vv.push_back(s[i][1]); } else if (mp1[s[i][0]] < mp1[s[i][1]]) { mp1[s[i][0]]++; mp1[s[i][1]]--; vv.push_back(s[i][0]); } else if (mp1[s[i][0]] == mp1[s[i][1]]) { if (mp1[s[i][0]] == 0) { ch = false; break; } if (i + 1 != n && (s[i][0] == s[i + 1][1] || s[i][0] == s[i + 1][0])) { vv.push_back(s[i][0]); mp1[s[i][0]]++; mp1[s[i][1]]--; } else { vv.push_back(s[i][1]); mp1[s[i][0]]--; mp1[s[i][1]]++; } } } if (!ch) cout << "No"; else { cout << "Yes" << endl; for (int i = 0; i < vv.size(); i++) cout << vv[i] << endl; } return 0; }
replace
108
109
108
110
0
p02692
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define ll long long #define ull unsigned long long #define vint vector<int> #define vll vector<ll> // #include <stack> // #include <queue> /* #include <math.h> int standerd = int(pow(10.0,9.0)) + 7; */ string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; ll ABC[4]; ll N; ll A; ll B; ll C; int main() { cin >> N; cin >> A; cin >> B; cin >> C; ABC[0] = A; ABC[1] = B; ABC[2] = C; string VAL[4]; VAL[0] = "A"; VAL[1] = "B"; VAL[2] = "C"; string flag = "Yes"; vector<string> ans; vector<string> ss; string sentaku; int index1; int index2; if (A == 0 && B == 0 && C == 0) { cout << "No" << endl; } else { rep(ni, N) { cin >> sentaku; ss.push_back(sentaku); } rep(ni, N) { sentaku = ss[ni]; if (sentaku == "AB") { index1 = 0; index2 = 1; } else if (sentaku == "BC") { index1 = 1; index2 = 2; } else { index1 = 0; index2 = 2; } if (ABC[index1] == 0 && ABC[index2] == 0) { flag = "No"; break; } else if (ABC[index1] == 1 && ABC[index2] == 1) { if (ss[ni + 1].substr(0, 1) == VAL[index1] && ss[ni + 1].substr(1, 1) == VAL[index2]) { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } else if (ss[ni + 1].substr(0, 1) == VAL[index1]) { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } else if (ss[ni + 1].substr(1, 1) == VAL[index1]) { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } else { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } } else { if (ABC[index1] >= ABC[index2]) { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } else { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } } } cout << flag << endl; if (flag == "Yes") { rep(ni, ans.size()) { cout << ans[ni] << endl; } } } }
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define ll long long #define ull unsigned long long #define vint vector<int> #define vll vector<ll> // #include <stack> // #include <queue> /* #include <math.h> int standerd = int(pow(10.0,9.0)) + 7; */ string ans_Yes = "Yes"; string ans_No = "No"; string ans_yes = "yes"; string ans_no = "no"; ll ABC[4]; ll N; ll A; ll B; ll C; int main() { cin >> N; cin >> A; cin >> B; cin >> C; ABC[0] = A; ABC[1] = B; ABC[2] = C; string VAL[4]; VAL[0] = "A"; VAL[1] = "B"; VAL[2] = "C"; string flag = "Yes"; vector<string> ans; vector<string> ss; string sentaku; int index1; int index2; if (A == 0 && B == 0 && C == 0) { cout << "No" << endl; } else { rep(ni, N) { cin >> sentaku; ss.push_back(sentaku); } rep(ni, N) { sentaku = ss[ni]; if (sentaku == "AB") { index1 = 0; index2 = 1; } else if (sentaku == "BC") { index1 = 1; index2 = 2; } else { index1 = 0; index2 = 2; } if (ABC[index1] == 0 && ABC[index2] == 0) { flag = "No"; break; } else if (ABC[index1] == 1 && ABC[index2] == 1 && ni + 1 < N) { if (ss[ni + 1].substr(0, 1) == VAL[index1]) { if (ss[ni + 1].substr(1, 1) == VAL[index2]) { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } else { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } } else if (ss[ni + 1].substr(1, 1) == VAL[index1]) { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } else { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } } else { if (ABC[index1] >= ABC[index2]) { ABC[index1]--; ABC[index2]++; ans.push_back(VAL[index2]); } else { ABC[index2]--; ABC[index1]++; ans.push_back(VAL[index1]); } } } cout << flag << endl; if (flag == "Yes") { rep(ni, ans.size()) { cout << ans[ni] << endl; } } } }
replace
76
86
76
87
0
p02692
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (auto &e : S) cin >> e; string ans = "", tmp = ""; auto dfs = [&](auto &&dfs, int i, int a, int b, int c) -> bool { if (a < 0 or b < 0 or c < 0) return false; if (i == N) { ans = tmp; return true; } bool res = false; if (S[i] == "AB") { tmp += 'A'; res |= dfs(dfs, i + 1, a + 1, b - 1, c); tmp[i] = 'B'; res |= dfs(dfs, i + 1, a - 1, b + 1, c); tmp.pop_back(); } else if (S[i] == "BC") { tmp += 'B'; res |= dfs(dfs, i + 1, a, b + 1, c - 1); tmp[i] = 'C'; res |= dfs(dfs, i + 1, a, b - 1, c + 1); tmp.pop_back(); } else if (S[i] == "AC") { tmp += 'A'; res |= dfs(dfs, i + 1, a + 1, b, c - 1); tmp[i] = 'C'; res |= dfs(dfs, i + 1, a - 1, b, c + 1); tmp.pop_back(); } return res; }; if (dfs(dfs, 0, A, B, C)) { cout << "Yes" << '\n'; for (auto &e : ans) cout << e << '\n'; } else { cout << "No" << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (auto &e : S) cin >> e; string ans = "", tmp = ""; auto dfs = [&](auto &&dfs, int i, int a, int b, int c) -> bool { if (!ans.empty()) return true; if (a < 0 or b < 0 or c < 0) return false; if (i == N) { ans = tmp; return true; } bool res = false; if (S[i] == "AB") { tmp += 'A'; res |= dfs(dfs, i + 1, a + 1, b - 1, c); tmp[i] = 'B'; res |= dfs(dfs, i + 1, a - 1, b + 1, c); tmp.pop_back(); } else if (S[i] == "BC") { tmp += 'B'; res |= dfs(dfs, i + 1, a, b + 1, c - 1); tmp[i] = 'C'; res |= dfs(dfs, i + 1, a, b - 1, c + 1); tmp.pop_back(); } else if (S[i] == "AC") { tmp += 'A'; res |= dfs(dfs, i + 1, a + 1, b, c - 1); tmp[i] = 'C'; res |= dfs(dfs, i + 1, a - 1, b, c + 1); tmp.pop_back(); } return res; }; if (dfs(dfs, 0, A, B, C)) { cout << "Yes" << '\n'; for (auto &e : ans) cout << e << '\n'; } else { cout << "No" << '\n'; } return 0; }
insert
12
12
12
14
TLE
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++) #define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--) #define sort_vec(v) sort((v).begin(), (v).end()) typedef int64_t lint; // lint mod = 998244353; template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } void app() { int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2]; vector<string> sv(n); rep(i, n) { cin >> sv[i]; } string ans; rep(i, n) { string s = sv[i]; int c = s[0] - 'A'; int d = s[1] - 'A'; if (a[c] < a[d]) { ans += 'A' + c; a[c]++; a[d]--; } else if (a[c] > a[d]) { ans += 'A' + d; a[d]++; a[c]--; } else if (i == n - 1 || s[i] == s[i + 1]) { ans += 'A' + c; a[c]++; a[d]--; } else { string sn = sv[i + 1]; int e = sn[0] - 'A'; int f = sn[1] - 'A'; if (c == e || c == f) { ans += 'A' + c; a[c]++; a[d]--; } else { ans += 'A' + d; a[d]++; a[c]--; } } if (a[0] < 0 || a[1] < 0 || a[2] < 0) { cout << "No" << endl; return; } } cout << "Yes" << endl; rep(i, n) { cout << ans[i] << endl; } } int main() { app(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++) #define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--) #define sort_vec(v) sort((v).begin(), (v).end()) typedef int64_t lint; // lint mod = 998244353; template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } void app() { int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2]; vector<string> sv(n); rep(i, n) { cin >> sv[i]; } string ans; rep(i, n) { string s = sv[i]; int c = s[0] - 'A'; int d = s[1] - 'A'; if (a[c] < a[d]) { ans += 'A' + c; a[c]++; a[d]--; } else if (a[c] > a[d]) { ans += 'A' + d; a[d]++; a[c]--; } else if (i == n - 1 || sv[i] == sv[i + 1]) { ans += 'A' + c; a[c]++; a[d]--; } else { string sn = sv[i + 1]; int e = sn[0] - 'A'; int f = sn[1] - 'A'; if (c == e || c == f) { ans += 'A' + c; a[c]++; a[d]--; } else { ans += 'A' + d; a[d]++; a[c]--; } } if (a[0] < 0 || a[1] < 0 || a[2] < 0) { cout << "No" << endl; return; } } cout << "Yes" << endl; rep(i, n) { cout << ans[i] << endl; } } int main() { app(); return 0; }
replace
36
37
36
37
0
p02692
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pa; #define fst first #define snd second #define pb push_back const int maxn = 300005, maxm = 106; const double pi = acos(-1.0); const ll mod = 1000000007; const double eps = 1e-6; int n, x[3]; bool fl = 1; char c[maxn] = {0}, tp[maxn]; int ii[maxn][2]; void dfs(int aa, int bb, int cc, int dep) { int i, j, k, l; int tmp[3] = {aa, bb, cc}; if (dep == n) { for (i = 0; i < n; i++) c[i] = tp[i]; return; } if (c[0] != 0) return; if (tmp[ii[dep][0]] > tmp[ii[dep][1]]) { tp[dep] = ii[dep][1] + 'A'; --tmp[ii[dep][0]]; ++tmp[ii[dep][1]]; dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][0]]; --tmp[ii[dep][1]]; } if (c[0] != 0) return; if (tmp[ii[dep][1]] > tmp[ii[dep][0]]) { tp[dep] = ii[dep][0] + 'A'; --tmp[ii[dep][1]]; ++tmp[ii[dep][0]]; dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][1]]; --tmp[ii[dep][0]]; } if (c[0] != 0) return; tp[dep] = ii[dep][1] + 'A'; --tmp[ii[dep][0]]; ++tmp[ii[dep][1]]; if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0) dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][0]]; --tmp[ii[dep][1]]; if (c[0] != 0) return; tp[dep] = ii[dep][0] + 'A'; --tmp[ii[dep][1]]; ++tmp[ii[dep][0]]; if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0) dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][1]]; --tmp[ii[dep][0]]; } int main() { int i, j, k, l; scanf("%d", &n); for (i = 0; i < 3; i++) scanf("%d", x + i); for (i = 0; i < n; i++) { char s[5]; scanf("%s", s); ii[i][0] = s[0] - 'A', ii[i][1] = s[1] - 'A'; } dfs(x[0], x[1], x[2], 0); printf("%s\n", c[0] != 0 ? "Yes" : "No"); if (c[0] != 0) { for (i = 0; i < n; i++) printf("%c\n", c[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pa; #define fst first #define snd second #define pb push_back const int maxn = 300005, maxm = 106; const double pi = acos(-1.0); const ll mod = 1000000007; const double eps = 1e-6; int n, x[3]; bool fl = 1; char c[maxn] = {0}, tp[maxn]; int ii[maxn][2]; void dfs(int aa, int bb, int cc, int dep) { int i, j, k, l; int tmp[3] = {aa, bb, cc}; if (dep == n) { for (i = 0; i < n; i++) c[i] = tp[i]; return; } if (c[0] != 0) return; if (tmp[ii[dep][0]] > tmp[ii[dep][1]]) { tp[dep] = ii[dep][1] + 'A'; --tmp[ii[dep][0]]; ++tmp[ii[dep][1]]; dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][0]]; --tmp[ii[dep][1]]; } if (c[0] != 0) return; if (tmp[ii[dep][1]] > tmp[ii[dep][0]]) { tp[dep] = ii[dep][0] + 'A'; --tmp[ii[dep][1]]; ++tmp[ii[dep][0]]; dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][1]]; --tmp[ii[dep][0]]; } if (c[0] != 0) return; if (tmp[ii[dep][1]] != tmp[ii[dep][0]]) return; tp[dep] = ii[dep][1] + 'A'; --tmp[ii[dep][0]]; ++tmp[ii[dep][1]]; if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0) dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][0]]; --tmp[ii[dep][1]]; if (c[0] != 0) return; tp[dep] = ii[dep][0] + 'A'; --tmp[ii[dep][1]]; ++tmp[ii[dep][0]]; if (tmp[0] >= 0 && tmp[1] >= 0 && tmp[2] >= 0) dfs(tmp[0], tmp[1], tmp[2], dep + 1); ++tmp[ii[dep][1]]; --tmp[ii[dep][0]]; } int main() { int i, j, k, l; scanf("%d", &n); for (i = 0; i < 3; i++) scanf("%d", x + i); for (i = 0; i < n; i++) { char s[5]; scanf("%s", s); ii[i][0] = s[0] - 'A', ii[i][1] = s[1] - 'A'; } dfs(x[0], x[1], x[2], 0); printf("%s\n", c[0] != 0 ? "Yes" : "No"); if (c[0] != 0) { for (i = 0; i < n; i++) printf("%c\n", c[i]); } return 0; }
insert
50
50
50
52
TLE
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define ALL(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } const int INF = 1e18; signed main() { int N, A, B, C; vi abc(3); cin >> N; int sum = 0; rep(i, 3) { cin >> abc[i]; sum += abc[i]; } V(P) S(N); rep(i, N) { string s; cin >> s; S[i] = P(s[0] - 'A', s[1] - 'A'); } vi res; // A+B+Cの合計で場合分け // 合計が0なら明らかに不可 if (sum == 0) { cout << "No" << endl; // 合計が1なら、解は1通りしか存在しない } else if (sum == 1) { rep(i, N) { if (abc[S[i].fi] == 0 && abc[S[i].se] == 0) { cout << "No" << endl; return 0; } else { if (abc[S[i].fi]) { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } else { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } } } // 合計が2以上なら、現在の状態とクエリでさらに場合分け } else { rep(i, N) { // クエリの文字の数が両方とも0なら、その時点で不可 if (abc[S[i].fi] == 0 && abc[S[i].se] == 0) { cout << "No" << endl; return 0; } // クエリの文字の数のうちどちらか一方が0なら、そちらに足す else if (abc[S[i].fi] == 0 || abc[S[i].se] == 0) { if (abc[S[i].fi]) { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } else { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } // クエリの文字の数が両方とも正なら、次のクエリを見て判定する // 次のクエリに含まれている文字のほうに足せば最適 // 次のクエリと現在のクエリが同じなら、好きなほうに足せばよい } else { if (i < N - 1) { P np = S[i + 1]; if (S[i].fi == np.fi || S[i].fi == np.se) { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } else { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } } else { res.pb(S[i].fi); } } } } cout << "Yes" << endl; rep(i, N) cout << char(res[i] + 'A') << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define ALL(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } const int INF = 1e18; signed main() { int N, A, B, C; vi abc(3); cin >> N; int sum = 0; rep(i, 3) { cin >> abc[i]; sum += abc[i]; } V(P) S(N); rep(i, N) { string s; cin >> s; S[i] = P(s[0] - 'A', s[1] - 'A'); } vi res; // A+B+Cの合計で場合分け // 合計が0なら明らかに不可 if (sum == 0) { cout << "No" << endl; return 0; // 合計が1なら、解は1通りしか存在しない } else if (sum == 1) { rep(i, N) { if (abc[S[i].fi] == 0 && abc[S[i].se] == 0) { cout << "No" << endl; return 0; } else { if (abc[S[i].fi]) { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } else { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } } } // 合計が2以上なら、現在の状態とクエリでさらに場合分け } else { rep(i, N) { // クエリの文字の数が両方とも0なら、その時点で不可 if (abc[S[i].fi] == 0 && abc[S[i].se] == 0) { cout << "No" << endl; return 0; } // クエリの文字の数のうちどちらか一方が0なら、そちらに足す else if (abc[S[i].fi] == 0 || abc[S[i].se] == 0) { if (abc[S[i].fi]) { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } else { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } // クエリの文字の数が両方とも正なら、次のクエリを見て判定する // 次のクエリに含まれている文字のほうに足せば最適 // 次のクエリと現在のクエリが同じなら、好きなほうに足せばよい } else { if (i < N - 1) { P np = S[i + 1]; if (S[i].fi == np.fi || S[i].fi == np.se) { res.pb(S[i].fi); abc[S[i].fi]++; abc[S[i].se]--; } else { res.pb(S[i].se); abc[S[i].fi]--; abc[S[i].se]++; } } else { res.pb(S[i].fi); } } } } cout << "Yes" << endl; rep(i, N) cout << char(res[i] + 'A') << endl; return 0; }
replace
54
55
54
55
0
p02692
C++
Runtime Error
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 2e5 + 5; const int Mod = 1e9 + 7; #define pi acos(-1) #define INF 1e9 + 5 #define INM INT_MIN #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define dbg(x) cout << "now this num is " << x << endl; #define met0(axx) memset(axx, 0, sizeof(axx)); #define metf(axx) memset(axx, -1, sizeof(axx)); #define sd(ax) scanf("%d", &ax) #define sld(ax) scanf("%lld", &ax) #define sldd(ax, bx) scanf("%lld %lld", &ax, &bx) #define sdd(ax, bx) scanf("%d %d", &ax, &bx) #define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx) #define sfd(ax) scanf("%lf", &ax) #define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx) #define pr(a) printf("%d\n", a) #define plr(a) printf("%lld\n", a) /* 贪心?pu..看zzl学长的贪心,emm..很微妙.也能过 但是可以直接dfs暴搜.. */ int n, f = 0; string s[N], ans; void dfs(int x, int y, int z, int i) { if (f) return; if (i == n + 1) { if (x >= 0 && y >= 0 && z >= 0) { f = 1; printf("Yes\n"); for (int i = 1; i <= n; ++i) cout << ans[i] << "\n"; } return; } if (s[i] == "AB") { if (y > 0) ans[i] = 'A', dfs(x + 1, y - 1, z, i + 1); if (x > 0) ans[i] = 'B', dfs(x - 1, y + 1, z, i + 1); } if (s[i] == "BC") { if (z > 0) ans[i] = 'B', dfs(x, y + 1, z - 1, i + 1); if (y > 0) ans[i] = 'C', dfs(x, y - 1, z + 1, i + 1); } if (s[i] == "AC") { if (z > 0) ans[i] = 'A', dfs(x + 1, y, z - 1, i + 1); if (x > 0) ans[i] = 'C', dfs(x - 1, y, z + 1, i + 1); } } int main() { sd(n); int a, b, c; sddd(a, b, c); for (int i = 1; i <= n; ++i) cin >> s[i]; dfs(a, b, c, 1); if (!f) printf("No\n"); // system("pause"); return 0; }
#include <algorithm> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 2e5 + 5; const int Mod = 1e9 + 7; #define pi acos(-1) #define INF 1e9 + 5 #define INM INT_MIN #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define dbg(x) cout << "now this num is " << x << endl; #define met0(axx) memset(axx, 0, sizeof(axx)); #define metf(axx) memset(axx, -1, sizeof(axx)); #define sd(ax) scanf("%d", &ax) #define sld(ax) scanf("%lld", &ax) #define sldd(ax, bx) scanf("%lld %lld", &ax, &bx) #define sdd(ax, bx) scanf("%d %d", &ax, &bx) #define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx) #define sfd(ax) scanf("%lf", &ax) #define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx) #define pr(a) printf("%d\n", a) #define plr(a) printf("%lld\n", a) /* 贪心?pu..看zzl学长的贪心,emm..很微妙.也能过 但是可以直接dfs暴搜.. */ int n, f = 0; string s[N]; char ans[N]; void dfs(int x, int y, int z, int i) { if (f) return; if (i == n + 1) { if (x >= 0 && y >= 0 && z >= 0) { f = 1; printf("Yes\n"); for (int i = 1; i <= n; ++i) cout << ans[i] << "\n"; } return; } if (s[i] == "AB") { if (y > 0) ans[i] = 'A', dfs(x + 1, y - 1, z, i + 1); if (x > 0) ans[i] = 'B', dfs(x - 1, y + 1, z, i + 1); } if (s[i] == "BC") { if (z > 0) ans[i] = 'B', dfs(x, y + 1, z - 1, i + 1); if (y > 0) ans[i] = 'C', dfs(x, y - 1, z + 1, i + 1); } if (s[i] == "AC") { if (z > 0) ans[i] = 'A', dfs(x + 1, y, z - 1, i + 1); if (x > 0) ans[i] = 'C', dfs(x - 1, y, z + 1, i + 1); } } int main() { sd(n); int a, b, c; sddd(a, b, c); for (int i = 1; i <= n; ++i) cin >> s[i]; dfs(a, b, c, 1); if (!f) printf("No\n"); // system("pause"); return 0; }
replace
38
39
38
40
0
p02692
C++
Runtime Error
#include <stdio.h> #include <string.h> int main() { int N, A[3], i, j, k, nj, nk; char s[3]; int ans[10000]; scanf("%d%d%d%d", &N, A, A + 1, A + 2); // if(A[0] + A[1] + A[2] == 0){ // printf("No"); // } scanf("%s", s); if (strcmp(s, "AB") == 0) { j = 0; k = 1; } if (strcmp(s, "AC") == 0) { j = 0; k = 2; } if (strcmp(s, "BC") == 0) { j = 1; k = 2; } for (i = 0; i < N; i++) { if (i != N - 1) { scanf("%s", s); if (strcmp(s, "AB") == 0) { nj = 0; nk = 1; } if (strcmp(s, "AC") == 0) { nj = 0; nk = 2; } if (strcmp(s, "BC") == 0) { nj = 1; nk = 2; } } if (A[j] == 0 && A[k] == 0) { printf("No"); // break; return 0; } if (A[j] == 0) { A[j]++; A[k]--; ans[i] = j; } else if (A[k] == 0) { A[j]--; A[k]++; ans[i] = k; } else if (i != N - 1) { if (j == nj || j == nk) { A[j]++; A[k]--; ans[i] = j; } else { A[j]--; A[k]++; ans[i] = k; } } else { A[j]++; A[k]--; ans[i] = j; } j = nj; k = nk; } printf("Yes\n"); for (i = 0; i < N; i++) { printf("%c\n", 'A' + ans[i]); } }
#include <stdio.h> #include <string.h> int main() { int N, A[3], i, j, k, nj, nk; char s[3]; int ans[100000]; scanf("%d%d%d%d", &N, A, A + 1, A + 2); // if(A[0] + A[1] + A[2] == 0){ // printf("No"); // } scanf("%s", s); if (strcmp(s, "AB") == 0) { j = 0; k = 1; } if (strcmp(s, "AC") == 0) { j = 0; k = 2; } if (strcmp(s, "BC") == 0) { j = 1; k = 2; } for (i = 0; i < N; i++) { if (i != N - 1) { scanf("%s", s); if (strcmp(s, "AB") == 0) { nj = 0; nk = 1; } if (strcmp(s, "AC") == 0) { nj = 0; nk = 2; } if (strcmp(s, "BC") == 0) { nj = 1; nk = 2; } } if (A[j] == 0 && A[k] == 0) { printf("No"); // break; return 0; } if (A[j] == 0) { A[j]++; A[k]--; ans[i] = j; } else if (A[k] == 0) { A[j]--; A[k]++; ans[i] = k; } else if (i != N - 1) { if (j == nj || j == nk) { A[j]++; A[k]--; ans[i] = j; } else { A[j]--; A[k]++; ans[i] = k; } } else { A[j]++; A[k]--; ans[i] = j; } j = nj; k = nk; } printf("Yes\n"); for (i = 0; i < N; i++) { printf("%c\n", 'A' + ans[i]); } }
replace
6
7
6
7
0
p02692
Python
Runtime Error
N, A, B, C = map(int, input().split()) opts = [] for _ in range(N): opt = input() opts.append((ord(opt[0]) - ord("A"), ord(opt[1]) - ord("A"))) choices = [] nums = [A, B, C] for i, opt in enumerate(opts): if nums[opt[0]] == 0 and nums[opt[1]] == 0: print("No") break if nums[opt[0]] == 1 and nums[opt[1]] == 1: if i < N - 1 and opt != opts[i + 1]: choice = next(set(opt) ^ set(opts[i + 1])) nums[opt] += 1 nums[opt ^ opt[0] ^ opt[1]] -= 1 choices.append(choice) continue if nums[opt[0]] >= nums[opt[1]]: choices.append(opt[1]) nums[opt[1]] += 1 nums[opt[0]] -= 1 else: choices.append(opt[0]) nums[opt[0]] += 1 nums[opt[1]] -= 1 else: print("Yes") for c in choices: print(chr(c + ord("A")))
N, A, B, C = map(int, input().split()) opts = [] for _ in range(N): opt = input() opts.append((ord(opt[0]) - ord("A"), ord(opt[1]) - ord("A"))) choices = [] nums = [A, B, C] for i, opt in enumerate(opts): if nums[opt[0]] == 0 and nums[opt[1]] == 0: print("No") break if nums[opt[0]] == 1 and nums[opt[1]] == 1: if i < N - 1 and opt != opts[i + 1]: choice = (set(opt) & set(opts[i + 1])).pop() nums[choice] += 1 nums[choice ^ opt[0] ^ opt[1]] -= 1 choices.append(choice) continue if nums[opt[0]] >= nums[opt[1]]: choices.append(opt[1]) nums[opt[1]] += 1 nums[opt[0]] -= 1 else: choices.append(opt[0]) nums[opt[0]] += 1 nums[opt[1]] -= 1 else: print("Yes") for c in choices: print(chr(c + ord("A")))
replace
14
17
14
17
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define odd(x) ((x)&1) #define even(x) (!odd(x)) #define ff it->first #define ss it->second #define all(v) (v).begin(), (v).end() #define rep(i, n) for (auto i = 0; i < n; ++i) #define LOOP_IT(it, s) for (auto it = (s).begin(); it != (s).end(); ++it) #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define TEST_CASE \ int tc; \ cin >> tc; \ while (tc--) #ifdef LOCAL #define cerr cout #else #endif #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif int main(int argv, char *argc[]) { FASTIO freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); int n, v[3]; bool f = 1; cin >> n >> v[0] >> v[1] >> v[2]; vector<set<int>> mp(3); vector<char> res(n); vector<string> s(n); rep(i, n) { cin >> s[i]; int x = s[i][0] - 'A', y = s[i][1] - 'A'; mp[x].insert(i); mp[y].insert(i); } rep(i, n) { int x = s[i][0] - 'A', y = s[i][1] - 'A'; if (v[x] > v[y]) { ++v[y], --v[x]; res[i] = (s[i][1]); } else if (v[x] == 1 && v[y] == 1) { auto it1 = mp[x].upper_bound(i); auto it2 = mp[y].upper_bound(i); if ((it2 == mp[y].end() || *it1 < *it2) && (it1 != mp[x].end())) { ++v[x], --v[y]; res[i] = (s[i][0]); } else { --v[x], ++v[y]; res[i] = (s[i][1]); } } else { --v[y], ++v[x]; res[i] = (s[i][0]); } if (v[x] < 0 || v[y] < 0) { f = 0; break; } } if (f) { cout << "Yes\n"; for (auto i : res) cout << i << "\n"; } else { cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define odd(x) ((x)&1) #define even(x) (!odd(x)) #define ff it->first #define ss it->second #define all(v) (v).begin(), (v).end() #define rep(i, n) for (auto i = 0; i < n; ++i) #define LOOP_IT(it, s) for (auto it = (s).begin(); it != (s).end(); ++it) #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define TEST_CASE \ int tc; \ cin >> tc; \ while (tc--) #ifdef LOCAL #define cerr cout #else #endif #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif int main(int argv, char *argc[]) { FASTIO // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int n, v[3]; bool f = 1; cin >> n >> v[0] >> v[1] >> v[2]; vector<set<int>> mp(3); vector<char> res(n); vector<string> s(n); rep(i, n) { cin >> s[i]; int x = s[i][0] - 'A', y = s[i][1] - 'A'; mp[x].insert(i); mp[y].insert(i); } rep(i, n) { int x = s[i][0] - 'A', y = s[i][1] - 'A'; if (v[x] > v[y]) { ++v[y], --v[x]; res[i] = (s[i][1]); } else if (v[x] == 1 && v[y] == 1) { auto it1 = mp[x].upper_bound(i); auto it2 = mp[y].upper_bound(i); if ((it2 == mp[y].end() || *it1 < *it2) && (it1 != mp[x].end())) { ++v[x], --v[y]; res[i] = (s[i][0]); } else { --v[x], ++v[y]; res[i] = (s[i][1]); } } else { --v[y], ++v[x]; res[i] = (s[i][0]); } if (v[x] < 0 || v[y] < 0) { f = 0; break; } } if (f) { cout << "Yes\n"; for (auto i : res) cout << i << "\n"; } else { cout << "No\n"; } return 0; }
replace
96
97
96
97
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02692
C++
Runtime Error
#include "bits/stdc++.h" #define FI first.first #define SE first.second #define TH second #define fi first #define se second #define th second using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif class DebugStream { } LOG; template <typename T> DebugStream &operator<<(DebugStream &s, const T &) { return s; } #ifdef DEBUG #define LOG clog #endif typedef long long ll; typedef pair<ll, ll> ii; typedef long double ld; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif int n; cin >> n; map<char, int> mp; cin >> mp['A'] >> mp['B'] >> mp['C']; vector<string> vc(n); for (auto &el : vc) cin >> el; for (int i = 0; i < n; i++) { char &p = vc[i][0], &q = vc[i][1]; if (mp[p] > mp[q] || (mp[p] == mp[q] && (i == n || vc[i + 1].find(q) != string::npos))) swap(p, q); mp[p]++, mp[q]--; if (mp[q] < 0) { cout << "No\n"; return 0; } } cout << "Yes\n"; for (auto el : vc) cout << el[0] << '\n'; }
#include "bits/stdc++.h" #define FI first.first #define SE first.second #define TH second #define fi first #define se second #define th second using namespace std; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef DEBUG #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif class DebugStream { } LOG; template <typename T> DebugStream &operator<<(DebugStream &s, const T &) { return s; } #ifdef DEBUG #define LOG clog #endif typedef long long ll; typedef pair<ll, ll> ii; typedef long double ld; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif int n; cin >> n; map<char, int> mp; cin >> mp['A'] >> mp['B'] >> mp['C']; vector<string> vc(n); for (auto &el : vc) cin >> el; for (int i = 0; i < n; i++) { char &p = vc[i][0], &q = vc[i][1]; if (mp[p] > mp[q] || (mp[p] == mp[q] && (i + 1 == n || vc[i + 1].find(q) != string::npos))) swap(p, q); mp[p]++, mp[q]--; if (mp[q] < 0) { cout << "No\n"; return 0; } } cout << "Yes\n"; for (auto el : vc) cout << el[0] << '\n'; }
replace
60
61
60
61
0
p02692
Python
Runtime Error
#!/usr/bin/env python3 S, stack = [], [] N = 0 def main() -> None: global N N, A, B, C = rmi() for n in range(N): S.append(r()) enable = dfs(stack, 0, A, B, C) w("Yes" if enable else "No") if enable: wm(*stack, delim="\n") def dfs(stack, index, a, b, c) -> bool: if N <= index: return True inst = S[index] if inst == "AB": if a <= 0 and b <= 0: return False if 0 < a: stack.append("B") result = dfs(stack, index + 1, a - 1, b + 1, c) if result: return True else: stack.pop() if 0 < b: stack.append("A") result = dfs(stack, index + 1, a + 1, b - 1, c) if result: return True else: stack.pop() elif inst == "AC": if a <= 0 and c <= 0: return False if 0 < a: stack.append("C") result = dfs(stack, index + 1, a - 1, b, c + 1) if result: return True else: stack.pop() if 0 < c: stack.append("A") result = dfs(stack, index + 1, a + 1, b, c - 1) if result: return True else: stack.pop() else: if b <= 0 and c <= 0: return False if 0 < b: stack.append("C") result = dfs(stack, index + 1, a, b - 1, c + 1) if result: return True else: stack.pop() if 0 < c: stack.append("B") result = dfs(stack, index + 1, a, b + 1, c - 1) if result: return True else: stack.pop() return False def r() -> str: return input().strip() def ri() -> int: return int(r()) def rmi(delim: str = " ") -> tuple: return tuple(map(int, input().split(delim))) def w(data) -> None: print(data) def wm(*data, delim: str = " ") -> None: print(delim.join(map(str, data))) if __name__ == "__main__": import sys sys.setrecursionlimit(10**10) main()
#!/usr/bin/env python3 S, stack = [], [] N = 0 def main() -> None: global N N, A, B, C = rmi() for n in range(N): S.append(r()) enable = dfs(stack, 0, A, B, C) w("Yes" if enable else "No") if enable: wm(*stack, delim="\n") def dfs(stack, index, a, b, c) -> bool: if N <= index: return True inst = S[index] if inst == "AB": if a <= 0 and b <= 0: return False if 0 < a: stack.append("B") result = dfs(stack, index + 1, a - 1, b + 1, c) if result: return True else: stack.pop() if 0 < b: stack.append("A") result = dfs(stack, index + 1, a + 1, b - 1, c) if result: return True else: stack.pop() elif inst == "AC": if a <= 0 and c <= 0: return False if 0 < a: stack.append("C") result = dfs(stack, index + 1, a - 1, b, c + 1) if result: return True else: stack.pop() if 0 < c: stack.append("A") result = dfs(stack, index + 1, a + 1, b, c - 1) if result: return True else: stack.pop() else: if b <= 0 and c <= 0: return False if 0 < b: stack.append("C") result = dfs(stack, index + 1, a, b - 1, c + 1) if result: return True else: stack.pop() if 0 < c: stack.append("B") result = dfs(stack, index + 1, a, b + 1, c - 1) if result: return True else: stack.pop() return False def r() -> str: return input().strip() def ri() -> int: return int(r()) def rmi(delim: str = " ") -> tuple: return tuple(map(int, input().split(delim))) def w(data) -> None: print(data) def wm(*data, delim: str = " ") -> None: print(delim.join(map(str, data))) if __name__ == "__main__": import sys sys.setrecursionlimit(10**9) main()
replace
99
100
99
100
OverflowError: Python int too large to convert to C int
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02692/Python/s269080943.py", line 99, in <module> sys.setrecursionlimit(10**10) OverflowError: Python int too large to convert to C int
p02692
Python
Runtime Error
n, a, b, c = (int(x) for x in input().split()) d = {"A": a, "B": b, "C": c} S = [input() for _ in range(n)] ANS = [] for i, s in enumerate(S): if d[s[0]] == 0 and d[s[1]] == 0: print("No") exit() else: if d[s[0]] > d[s[1]] or ( d[s[0]] == d[s[1]] == 1 and i < n and s[1] in S[i + 1] ): d[s[1]] += 1 d[s[0]] -= 1 ANS.append(s[1]) else: d[s[0]] += 1 d[s[1]] -= 1 ANS.append(s[0]) print("Yes") for ans in ANS: print(ans)
n, a, b, c = (int(x) for x in input().split()) d = {"A": a, "B": b, "C": c} S = [input() for _ in range(n)] ANS = [] for i, s in enumerate(S): if d[s[0]] == 0 and d[s[1]] == 0: print("No") exit() else: if d[s[0]] > d[s[1]] or ( d[s[0]] == d[s[1]] == 1 and i < n - 1 and s[1] in S[i + 1] ): d[s[1]] += 1 d[s[0]] -= 1 ANS.append(s[1]) else: d[s[0]] += 1 d[s[1]] -= 1 ANS.append(s[0]) print("Yes") for ans in ANS: print(ans)
replace
11
12
11
12
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define eps 1e-8 // #define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const ll mod = 998244353; long double PI = acosl(-1); const ll infl = 3e18 + 10; const int inf = 1e9 + 10; const int nmax = 1e5 + 5; const int MAXLG = log2(nmax) + 1; // mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // typedef tree< int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> ost; void NA() { cout << "No"; exit(0); } bool dp[nmax][3][3][3]; /// n, a, b, c char dp2[nmax][3][3][3]; /// n, a, b, c int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, a, b, c; cin >> n; cin >> a >> b >> c; vector<string> s(n); for (auto &z : s) cin >> z; ll sam = a + b + c; string ans; if (sam == 2) { int hui = 0; dp[hui][a][b][c] = true; for (string z : s) { hui++; if (z == "AB") { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (i > 0) dp[hui][i - 1][j + 1][k] = true, dp2[hui][i - 1][j + 1][k] = 'B'; if (j > 0) dp[hui][i + 1][j - 1][k] = true, dp2[hui][i + 1][j - 1][k] = 'A'; } } else if (z == "AC") { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (i > 0) dp[hui][i - 1][j][k + 1] = true, dp2[hui][i - 1][j][k + 1] = 'C'; if (k > 0) dp[hui][i + 1][j][k - 1] = true, dp2[hui][i + 1][j][k - 1] = 'A'; } } else { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (j > 0) dp[hui][i][j - 1][k + 1] = true, dp2[hui][i][j - 1][k + 1] = 'C'; if (k > 0) dp[hui][i][j + 1][k - 1] = true, dp2[hui][i][j + 1][k - 1] = 'B'; } } // for(int i=0; i<2; i++) for(int j=0; j<2; j++) for(int k=0; // k<2; k++) if(dp[hui][i][j][k]){ // cout<<"possibul "<<hui<<" "<<i<<" "<<j<<" "<<k<<endl; // } } for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[n][i][j][k]) { while (n) { ans += dp2[n][i][j][k]; n--; if (ans.back() == 'A' and s[n] == "AB") i--, j++; else if (ans.back() == 'B' and s[n] == "AB") i++, j--; else if (ans.back() == 'A' and s[n] == "AC") i--, k++; else if (ans.back() == 'C' and s[n] == "AC") i++, k--; else if (ans.back() == 'B' and s[n] == "BC") j--, k++; else if (ans.back() == 'C' and s[n] == "BC") j++, k--; } reverse(ans.begin(), ans.end()); cout << "Yes\n"; for (auto z : ans) cout << z << "\n"; exit(0); } assert(false); } else { for (string z : s) { if (z == "AB") { if (a == 0 and b == 0) NA(); if (a > b) a--, b++, ans += 'B'; else a++, b--, ans += 'A'; } else if (z == "AC") { if (a == 0 and c == 0) NA(); if (a > c) a--, c++, ans += 'C'; else a++, c--, ans += 'A'; } else { if (c == 0 and b == 0) NA(); if (c > b) c--, b++, ans += 'B'; else c++, b--, ans += 'C'; } } cout << "Yes\n"; for (auto z : ans) cout << z << "\n"; } } /* 3 1 1 0 AB AC BC */
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define eps 1e-8 // #define eq(x,y) (fabs((x)-(y)) < eps) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const ll mod = 998244353; long double PI = acosl(-1); const ll infl = 3e18 + 10; const int inf = 1e9 + 10; const int nmax = 1e5 + 5; const int MAXLG = log2(nmax) + 1; // mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); // typedef tree< int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> ost; void NA() { cout << "No"; exit(0); } bool dp[nmax][3][3][3]; /// n, a, b, c char dp2[nmax][3][3][3]; /// n, a, b, c int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n, a, b, c; cin >> n; cin >> a >> b >> c; vector<string> s(n); for (auto &z : s) cin >> z; ll sam = a + b + c; string ans; if (sam == 2) { int hui = 0; dp[hui][a][b][c] = true; for (string z : s) { hui++; if (z == "AB") { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (i > 0) dp[hui][i - 1][j + 1][k] = true, dp2[hui][i - 1][j + 1][k] = 'B'; if (j > 0) dp[hui][i + 1][j - 1][k] = true, dp2[hui][i + 1][j - 1][k] = 'A'; } } else if (z == "AC") { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (i > 0) dp[hui][i - 1][j][k + 1] = true, dp2[hui][i - 1][j][k + 1] = 'C'; if (k > 0) dp[hui][i + 1][j][k - 1] = true, dp2[hui][i + 1][j][k - 1] = 'A'; } } else { for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[hui - 1][i][j][k]) { if (j > 0) dp[hui][i][j - 1][k + 1] = true, dp2[hui][i][j - 1][k + 1] = 'C'; if (k > 0) dp[hui][i][j + 1][k - 1] = true, dp2[hui][i][j + 1][k - 1] = 'B'; } } // for(int i=0; i<2; i++) for(int j=0; j<2; j++) for(int k=0; // k<2; k++) if(dp[hui][i][j][k]){ // cout<<"possibul "<<hui<<" "<<i<<" "<<j<<" "<<k<<endl; // } } for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) for (int k = 0; k <= 2; k++) if (dp[n][i][j][k]) { while (n) { ans += dp2[n][i][j][k]; n--; if (ans.back() == 'A' and s[n] == "AB") i--, j++; else if (ans.back() == 'B' and s[n] == "AB") i++, j--; else if (ans.back() == 'A' and s[n] == "AC") i--, k++; else if (ans.back() == 'C' and s[n] == "AC") i++, k--; else if (ans.back() == 'B' and s[n] == "BC") j--, k++; else if (ans.back() == 'C' and s[n] == "BC") j++, k--; } reverse(ans.begin(), ans.end()); cout << "Yes\n"; for (auto z : ans) cout << z << "\n"; exit(0); } NA(); // assert(false); } else { for (string z : s) { if (z == "AB") { if (a == 0 and b == 0) NA(); if (a > b) a--, b++, ans += 'B'; else a++, b--, ans += 'A'; } else if (z == "AC") { if (a == 0 and c == 0) NA(); if (a > c) a--, c++, ans += 'C'; else a++, c--, ans += 'A'; } else { if (c == 0 and b == 0) NA(); if (c > b) c--, b++, ans += 'B'; else c++, b--, ans += 'C'; } } cout << "Yes\n"; for (auto z : ans) cout << z << "\n"; } } /* 3 1 1 0 AB AC BC */
replace
115
116
115
117
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define M 1000000007 #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long int #define mem(x) memset(x, 0, sizeof(x)) #define setbits(x) __builtin_popcount(x) #define ull unsigned long long int #define rep(i, a, b) for (int i = a; i < b; i++) #define rep1(i, b, a) for (int i = b; i > a; i--) #define all(c) (c).begin(), (c).end() #define debug(x) cout << #x << " :: " << x << endl; #define debug2(x, y) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl; #define cps CLOCKS_PER_SEC #define complex \ cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n'; #define db double #define endl "\n" #define fbo(x) find_by_order(x) #define ook(x) order_of_key(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os1; typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> os2; inline void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll mod = (ll)(1e9) + 7; ll pmod(ll x, ll n) { ll r = 1; while (n) { if (n & 1LL) r = (r * x) % mod; x = (x * x) % mod; n = n / 2; } return r; } // think recursively also ll n; ll a, b, c; string s[100005]; int dp[100002][3][3][3]; bool sol(int in, ll ca, ll cb, ll cc) { if (ca < 0 || cb < 0 || cc < 0) return 0; if (in == n + 1) { dp[in + 1][ca][cb][cc] = 1; return 1; } if (dp[in][ca][cb][cc] != -1) return dp[in][ca][cb][cc]; bool ans = 0; if (s[in] == "AB") { int pp = cb + 1; int qq = ca + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, ca - 1, pp, cc); ans |= sol(in + 1, qq, cb - 1, cc); } else if (s[in] == "BC") { int pp = cb + 1; int qq = cc + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, ca, pp, cc - 1); ans |= sol(in + 1, ca, cb - 1, qq); } else if (s[in] == "AC") { int pp = ca + 1; int qq = cc + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, pp, cb, cc - 1); ans |= sol(in + 1, ca - 1, cb, qq); } dp[in][ca][cb][cc] = ans; return ans; } void go(int in, int a, int b, int c) { if (in == n + 1) return; if (s[in] == "AB") { int pp = a + 1; int qq = b + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a - 1, qq, c)) { cout << "B" << endl; go(in + 1, a - 1, qq, c); } else { cout << "A" << endl; go(in + 1, pp, b - 1, c); } } else if (s[in] == "BC") { int pp = b + 1; int qq = c + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a, b - 1, qq)) { cout << "C" << endl; go(in + 1, a, b - 1, qq); } else { cout << "B" << endl; go(in + 1, a, pp, c - 1); } } else if (s[in] == "AC") { int pp = a + 1; int qq = c + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a - 1, b, qq)) { cout << "C" << endl; go(in + 1, a - 1, b, qq); } else { cout << "A" << endl; go(in + 1, pp, b, c - 1); } } } void solve() { cin >> n >> a >> b >> c; for (int i = 1; i <= n; i++) { cin >> s[i]; } memset(dp, -1, sizeof(dp)); a = min(a, 2LL); b = min(b, 2LL); c = min(c, 2LL); if (sol(1, a, b, c)) { cout << "Yes" << endl; go(1, a, b, c); } else { cout << "No" << endl; } } int main() { fast(); // int t; // cin>>t; // for(int casee=1;casee<=t;casee++) { // cout<<"Case #"<<casee<<": "; solve(); } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define M 1000000007 #define pb push_back #define mp make_pair #define ff first #define ss second #define ll long long int #define mem(x) memset(x, 0, sizeof(x)) #define setbits(x) __builtin_popcount(x) #define ull unsigned long long int #define rep(i, a, b) for (int i = a; i < b; i++) #define rep1(i, b, a) for (int i = b; i > a; i--) #define all(c) (c).begin(), (c).end() #define debug(x) cout << #x << " :: " << x << endl; #define debug2(x, y) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl; #define cps CLOCKS_PER_SEC #define complex \ cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n'; #define db double #define endl "\n" #define fbo(x) find_by_order(x) #define ook(x) order_of_key(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os1; typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> os2; inline void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll mod = (ll)(1e9) + 7; ll pmod(ll x, ll n) { ll r = 1; while (n) { if (n & 1LL) r = (r * x) % mod; x = (x * x) % mod; n = n / 2; } return r; } // think recursively also ll n; ll a, b, c; string s[100005]; int dp[100002][3][3][3]; bool sol(int in, ll ca, ll cb, ll cc) { if (ca < 0 || cb < 0 || cc < 0) return 0; if (in == n + 1) { return 1; } if (dp[in][ca][cb][cc] != -1) return dp[in][ca][cb][cc]; bool ans = 0; if (s[in] == "AB") { int pp = cb + 1; int qq = ca + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, ca - 1, pp, cc); ans |= sol(in + 1, qq, cb - 1, cc); } else if (s[in] == "BC") { int pp = cb + 1; int qq = cc + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, ca, pp, cc - 1); ans |= sol(in + 1, ca, cb - 1, qq); } else if (s[in] == "AC") { int pp = ca + 1; int qq = cc + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; ans |= sol(in + 1, pp, cb, cc - 1); ans |= sol(in + 1, ca - 1, cb, qq); } dp[in][ca][cb][cc] = ans; return ans; } void go(int in, int a, int b, int c) { if (in == n + 1) return; if (s[in] == "AB") { int pp = a + 1; int qq = b + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a - 1, qq, c)) { cout << "B" << endl; go(in + 1, a - 1, qq, c); } else { cout << "A" << endl; go(in + 1, pp, b - 1, c); } } else if (s[in] == "BC") { int pp = b + 1; int qq = c + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a, b - 1, qq)) { cout << "C" << endl; go(in + 1, a, b - 1, qq); } else { cout << "B" << endl; go(in + 1, a, pp, c - 1); } } else if (s[in] == "AC") { int pp = a + 1; int qq = c + 1; if (pp > 2) pp = 2; if (qq > 2) qq = 2; if (sol(in + 1, a - 1, b, qq)) { cout << "C" << endl; go(in + 1, a - 1, b, qq); } else { cout << "A" << endl; go(in + 1, pp, b, c - 1); } } } void solve() { cin >> n >> a >> b >> c; for (int i = 1; i <= n; i++) { cin >> s[i]; } memset(dp, -1, sizeof(dp)); a = min(a, 2LL); b = min(b, 2LL); c = min(c, 2LL); if (sol(1, a, b, c)) { cout << "Yes" << endl; go(1, a, b, c); } else { cout << "No" << endl; } } int main() { fast(); // int t; // cin>>t; // for(int casee=1;casee<=t;casee++) { // cout<<"Case #"<<casee<<": "; solve(); } }
delete
63
64
63
63
0
p02692
C++
Runtime Error
#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n, k) (((ll)n >> (ll)k) & 1) /*nのk bit目*/ #define pb push_back #define pf push_front #define FI first #define SE second #define eb emplace_back #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const long long INF = 1e+18 + 1; // long long INF=(1LL<<31)-1; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; typedef struct Point_Coordinates { ll x, y; } point; const ll MOD = 1000000007LL; // ll MOD=1000000007LL; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; // const ll MAX_V=114514LL; // const ll MAX = 500010LL; const ll mod = MOD; string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx = {0, 0, 1, -1}; vl dy = {1, -1, 0, 0}; // 素因数分解O(√n) map<ll, ll> prime_factor(ll n) { map<ll, ll> res; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } const ll MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // finvが階乗の逆元 // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } /*Eratosthenes() ll N=2000010; vl arr(N); void Eratosthenes(){ for(ll i = 0; i < N; i++){ arr[i] = 1; } arr[1]=0; for(ll i = 2; i < sqrt(N); i++){ if(arr[i]){ for(ll j = 0; i * (j + 2) < N; j++){ arr[i *(j + 2)] = 0; } } } }*/ // 素数判定O(√n) bool is_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } // 約数の列挙O(√n) vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } return res; } /* SegTree<X>(n,fx,ex): モノイド(集合X, 二項演算fx, 単位元ex)についてサイズnで構築 set(int i, X x), build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n) update(i,x): i 番目の要素を x に更新。O(log(n)) query(a,b): [a,b) 全てにfxを作用させた値を取得。O(log(n)) */ template <typename X> struct SegTree { using FX = function<X(X, X)>; int n; FX fx; const X ex; vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } // the minimum element of [a,b) X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } /* debug */ inline X operator[](int a) { return query(a, a + 1); } void print() { for (int i = 0; i < 2 * n - 1; ++i) { cout << (*this)[i]; if (i != n) cout << ","; } cout << endl; } /* 使用例 auto fx=[](int x1,int x2)->int{return max(x1,x2);}; ll ex=0; SegTree<ll>rmq(n,fx,ex);*/ }; /* Trie 木: 文字の種類(char_size)、int型で0に対応する文字(base) insert(word): 単語 word を Trie 木に挿入する search(word): 単語 word が Trie 木にあるか判定する start_with(prefix): prefix が一致する単語が Trie 木にあるか判定する count(): 挿入した単語の数を返す size(): Trie 木の頂点数を返す 計算量:insert, search ともに O(M)(Mは単語の長さ) */ template <int char_size, int base> struct Trie { struct Node { // 頂点を表す構造体 vector<int> next; // 子の頂点番号を格納。存在しなければ-1 vector<int> accept; // 末端がこの頂点になる単語の word_id を保存 int c; // base からの間隔をint型で表現したもの int common; // いくつの単語がこの頂点を共有しているか Node(int c_) : c(c_), common(0) { next.assign(char_size, -1); } }; vector<Node> nodes; // trie 木本体 int root; Trie() : root(0) { nodes.push_back(Node(root)); } // 単語の挿入 void insert(const string &word, int word_id) { int node_id = 0; for (int i = 0; i < (int)word.size(); i++) { int c = (int)(word[i] - base); int &next_id = nodes[node_id].next[c]; if (next_id == -1) { // 次の頂点が存在しなければ追加 next_id = (int)nodes.size(); nodes.push_back(Node(c)); } ++nodes[node_id].common; node_id = next_id; } ++nodes[node_id].common; nodes[node_id].accept.push_back(word_id); } void insert(const string &word) { insert(word, nodes[0].common); } // 単語とprefixの検索 bool search(const string &word, bool prefix = false) { int node_id = 0; for (int i = 0; i < (int)word.size(); i++) { int c = (int)(word[i] - base); int &next_id = nodes[node_id].next[c]; if (next_id == -1) { // 次の頂点が存在しなければ終了 return false; } node_id = next_id; } return (prefix) ? true : nodes[node_id].accept.size() > 0; } // prefix を持つ単語が存在するかの検索 bool start_with(const string &prefix) { return search(prefix, true); } // 挿入した単語の数 int count() const { return (nodes[0].common); } // Trie木のノード数 int size() const { return ((int)nodes.size()); } }; // union by size + path having class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // 0-indexed parmutation only vvl cycle_partition(const vl &p) { ll n = p.size(); vvl ret; vector<bool> check(n, false); rep(i, n) if (!check[p[i]]) { vl v; ll pos = p[i]; v.pb(i); check[i] = true; while (pos != i) { v.pb(pos); check[pos] = true; pos = p[pos]; } ret.pb(v); } return ret; } // Manachar 修理中 // vl Manachar(string S){ // ll c=0,n=S.size(); // vl R(n,1); // for(ll i=0;i<n;i++){ // ll l=c-(i-c); // if(i+R[l]<c+R[c]){ // R[i]=R[l]; // }else{ // ll j=c+R[c]-i; // while(i-j>=0 && i+j<n && S[i-j] == S[i+j])j++; // R[i]=j; // c=i; // } // } // return R; // } struct edge { ll to; ll cost; }; template <typename T> T pow(T a, long long n, T e = 1) { T ret = e; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; } ModInt &operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; } ModInt &operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; } ModInt &operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod; return *this; } ModInt &operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod; return *this; } ModInt operator-() const { return -x < 0 ? mod - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return pow(*this, mod - 2); } friend ostream &operator<<(ostream &s, ModInt<mod> a) { s << a.x; return s; } friend istream &operator>>(istream &s, ModInt<mod> &a) { s >> a.x; return s; } }; using mint = ModInt<MOD>; /* RMQ:[0,n-1] について、区間ごとの最小値を管理する構造体 update(a,b,x): 区間[a,b) の要素を x に更新。O(log(n)) query(a,b): [a,b) での最小の要素を取得。O(log(n)) */ template <typename T> struct RMQ { // const T INF = numeric_limits<T>::max(); int n; vector<T> dat, lazy; RMQ(int n_) : n(), dat(n_ * 4, INF), lazy(n_ * 4, INF) { int x = 1; while (n_ > x) x *= 2; n = x; } /* lazy eval */ void eval(int k) { if (lazy[k] == INF) return; // 更新するものが無ければ終了 if (k < n - 1) { // 葉でなければ子に伝搬 lazy[k * 2 + 1] = lazy[k]; lazy[k * 2 + 2] = lazy[k]; } // 自身を更新 dat[k] = lazy[k]; lazy[k] = INF; } void update(int a, int b, T x, int k, int l, int r) { eval(k); if (a <= l && r <= b) { // 完全に内側の時 lazy[k] = x; eval(k); } else if (a < r && l < b) { // 一部区間が被る時 update(a, b, x, k * 2 + 1, l, (l + r) / 2); // 左の子 update(a, b, x, k * 2 + 2, (l + r) / 2, r); // 右の子 dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); } } void update(int a, int b, T x) { update(a, b, x, 0, 0, n); } T query_sub(int a, int b, int k, int l, int r) { eval(k); if (r <= a || b <= l) { // 完全に外側の時 return INF; } else if (a <= l && r <= b) { // 完全に内側の時 return dat[k]; } else { // 一部区間が被る時 T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } } T query(int a, int b) { return query_sub(a, b, 0, 0, n); } /* debug */ inline T operator[](int a) { return query(a, a + 1); } void print() { for (int i = 0; i < 2 * n - 1; ++i) { cout << (*this)[i]; if (i != n) cout << ","; } cout << endl; } }; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(10); /*--------------------------------*/ ll n, a, b, c; cin >> n >> a >> b >> c; vector<string> s(n); rep(i, n) cin >> s[i]; if (a == 0 and b == 0 and c == 0) { cout << "No" << endl; return 0; } vector<char> ans; if (a + b + c == 1) { rep(i, n) { if (s[i] == "AB") { if (a == 0 and b == 0) { cout << "No" << endl; return 0; } if (a == 1) { a--; b++; ans.pb('B'); } else { b--; a++; ans.pb('A'); } } if (s[i] == "AC") { if (a == 0 and c == 0) { cout << "No" << endl; return 0; } if (a == 1) { a--; c++; ans.pb('C'); } else { c--; a++; ans.pb('A'); } } if (s[i] == "BC") { if (b == 0 and c == 0) { cout << "No" << endl; return 0; } if (b == 1) { b--; c++; ans.pb('C'); } else { c--; b++; ans.pb('B'); } } } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; } if (s[0] == "AB") { if (a == 0 and b == 0) { cout << "No" << endl; return 0; } } if (s[0] == "AC") { if (a == 0 and c == 0) { cout << "No" << endl; return 0; } } if (s[0] == "BC") { if (b == 0 and c == 0) { cout << "No" << endl; return 0; } } rep(i, n - 1) { if (s[i] == "AB") { if (a > 0 and b == 0) { a--; b++; ans.pb('B'); } else if (a == 0 and b > 0) { a++; b--; ans.pb('A'); } } else if (s[i] == "AC") { if (a > 0 and c == 0) { a--; c++; ans.pb('C'); } else if (a == 0 and c > 0) { a++; c--; ans.pb('A'); } } else if (s[i] == "BC") { if (b > 0 and c == 0) { b--; c++; ans.pb('C'); } else if (b == 0 and c > 0) { b++; c--; ans.pb('B'); } } else if (s[i] == "AB" and s[i + 1] == "AB") { if (a >= b) { b++; a--; ans.pb('B'); } else { b--; a++; ans.pb('A'); } } else if (s[i] == "AC" and s[i + 1] == "AC") { if (a >= c) { c++; a--; ans.pb('C'); } else { c--; a++; ans.pb('A'); } } else if (s[i] == "BC" and s[i + 1] == "BC") { if (c >= b) { b++; c--; ans.pb('B'); } else { b--; c++; ans.pb('C'); } } else if (s[i] == "AC" and s[i + 1] == "AB") { a++; c--; ans.pb('A'); } else if (s[i] == "AC" and s[i + 1] == "BC") { c++; a--; ans.pb('C'); } else if (s[i] == "AB" and s[i + 1] == "AC") { a++; b--; ans.pb('A'); } else if (s[i] == "AB" and s[i + 1] == "BC") { b++; a--; ans.pb('B'); } else if (s[i] == "BC" and s[i + 1] == "AB") { b++; c--; ans.pb('B'); } else { c++; b--; ans.pb('C'); } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } } if (s[n - 1] == "AB") { if (a > 0) ans.pb('B'); else if (b > 0) ans.pb('A'); else { cout << "No" << endl; return 0; } } if (s[n - 1] == "BC") { if (b > 0) ans.pb('C'); else if (c > 0) ans.pb('B'); else { cout << "No" << endl; return 0; } } if (s[n - 1] == "AC") { if (a > 0) ans.pb('C'); else if (c > 0) ans.pb('A'); else { cout << "No" << endl; return 0; } } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; }
#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n, k) (((ll)n >> (ll)k) & 1) /*nのk bit目*/ #define pb push_back #define pf push_front #define FI first #define SE second #define eb emplace_back #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const long long INF = 1e+18 + 1; // long long INF=(1LL<<31)-1; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; typedef struct Point_Coordinates { ll x, y; } point; const ll MOD = 1000000007LL; // ll MOD=1000000007LL; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; // const ll MAX_V=114514LL; // const ll MAX = 500010LL; const ll mod = MOD; string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx = {0, 0, 1, -1}; vl dy = {1, -1, 0, 0}; // 素因数分解O(√n) map<ll, ll> prime_factor(ll n) { map<ll, ll> res; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } const ll MAX = 2000010; long long fac[MAX], finv[MAX], inv[MAX]; // finvが階乗の逆元 // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } /*Eratosthenes() ll N=2000010; vl arr(N); void Eratosthenes(){ for(ll i = 0; i < N; i++){ arr[i] = 1; } arr[1]=0; for(ll i = 2; i < sqrt(N); i++){ if(arr[i]){ for(ll j = 0; i * (j + 2) < N; j++){ arr[i *(j + 2)] = 0; } } } }*/ // 素数判定O(√n) bool is_prime(ll n) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return n != 1; } // 約数の列挙O(√n) vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } return res; } /* SegTree<X>(n,fx,ex): モノイド(集合X, 二項演算fx, 単位元ex)についてサイズnで構築 set(int i, X x), build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n) update(i,x): i 番目の要素を x に更新。O(log(n)) query(a,b): [a,b) 全てにfxを作用させた値を取得。O(log(n)) */ template <typename X> struct SegTree { using FX = function<X(X, X)>; int n; FX fx; const X ex; vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } // the minimum element of [a,b) X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } /* debug */ inline X operator[](int a) { return query(a, a + 1); } void print() { for (int i = 0; i < 2 * n - 1; ++i) { cout << (*this)[i]; if (i != n) cout << ","; } cout << endl; } /* 使用例 auto fx=[](int x1,int x2)->int{return max(x1,x2);}; ll ex=0; SegTree<ll>rmq(n,fx,ex);*/ }; /* Trie 木: 文字の種類(char_size)、int型で0に対応する文字(base) insert(word): 単語 word を Trie 木に挿入する search(word): 単語 word が Trie 木にあるか判定する start_with(prefix): prefix が一致する単語が Trie 木にあるか判定する count(): 挿入した単語の数を返す size(): Trie 木の頂点数を返す 計算量:insert, search ともに O(M)(Mは単語の長さ) */ template <int char_size, int base> struct Trie { struct Node { // 頂点を表す構造体 vector<int> next; // 子の頂点番号を格納。存在しなければ-1 vector<int> accept; // 末端がこの頂点になる単語の word_id を保存 int c; // base からの間隔をint型で表現したもの int common; // いくつの単語がこの頂点を共有しているか Node(int c_) : c(c_), common(0) { next.assign(char_size, -1); } }; vector<Node> nodes; // trie 木本体 int root; Trie() : root(0) { nodes.push_back(Node(root)); } // 単語の挿入 void insert(const string &word, int word_id) { int node_id = 0; for (int i = 0; i < (int)word.size(); i++) { int c = (int)(word[i] - base); int &next_id = nodes[node_id].next[c]; if (next_id == -1) { // 次の頂点が存在しなければ追加 next_id = (int)nodes.size(); nodes.push_back(Node(c)); } ++nodes[node_id].common; node_id = next_id; } ++nodes[node_id].common; nodes[node_id].accept.push_back(word_id); } void insert(const string &word) { insert(word, nodes[0].common); } // 単語とprefixの検索 bool search(const string &word, bool prefix = false) { int node_id = 0; for (int i = 0; i < (int)word.size(); i++) { int c = (int)(word[i] - base); int &next_id = nodes[node_id].next[c]; if (next_id == -1) { // 次の頂点が存在しなければ終了 return false; } node_id = next_id; } return (prefix) ? true : nodes[node_id].accept.size() > 0; } // prefix を持つ単語が存在するかの検索 bool start_with(const string &prefix) { return search(prefix, true); } // 挿入した単語の数 int count() const { return (nodes[0].common); } // Trie木のノード数 int size() const { return ((int)nodes.size()); } }; // union by size + path having class UnionFind { public: vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; // 0-indexed parmutation only vvl cycle_partition(const vl &p) { ll n = p.size(); vvl ret; vector<bool> check(n, false); rep(i, n) if (!check[p[i]]) { vl v; ll pos = p[i]; v.pb(i); check[i] = true; while (pos != i) { v.pb(pos); check[pos] = true; pos = p[pos]; } ret.pb(v); } return ret; } // Manachar 修理中 // vl Manachar(string S){ // ll c=0,n=S.size(); // vl R(n,1); // for(ll i=0;i<n;i++){ // ll l=c-(i-c); // if(i+R[l]<c+R[c]){ // R[i]=R[l]; // }else{ // ll j=c+R[c]-i; // while(i-j>=0 && i+j<n && S[i-j] == S[i+j])j++; // R[i]=j; // c=i; // } // } // return R; // } struct edge { ll to; ll cost; }; template <typename T> T pow(T a, long long n, T e = 1) { T ret = e; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; } ModInt &operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; } ModInt &operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; } ModInt &operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod; return *this; } ModInt &operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod; return *this; } ModInt operator-() const { return -x < 0 ? mod - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return pow(*this, mod - 2); } friend ostream &operator<<(ostream &s, ModInt<mod> a) { s << a.x; return s; } friend istream &operator>>(istream &s, ModInt<mod> &a) { s >> a.x; return s; } }; using mint = ModInt<MOD>; /* RMQ:[0,n-1] について、区間ごとの最小値を管理する構造体 update(a,b,x): 区間[a,b) の要素を x に更新。O(log(n)) query(a,b): [a,b) での最小の要素を取得。O(log(n)) */ template <typename T> struct RMQ { // const T INF = numeric_limits<T>::max(); int n; vector<T> dat, lazy; RMQ(int n_) : n(), dat(n_ * 4, INF), lazy(n_ * 4, INF) { int x = 1; while (n_ > x) x *= 2; n = x; } /* lazy eval */ void eval(int k) { if (lazy[k] == INF) return; // 更新するものが無ければ終了 if (k < n - 1) { // 葉でなければ子に伝搬 lazy[k * 2 + 1] = lazy[k]; lazy[k * 2 + 2] = lazy[k]; } // 自身を更新 dat[k] = lazy[k]; lazy[k] = INF; } void update(int a, int b, T x, int k, int l, int r) { eval(k); if (a <= l && r <= b) { // 完全に内側の時 lazy[k] = x; eval(k); } else if (a < r && l < b) { // 一部区間が被る時 update(a, b, x, k * 2 + 1, l, (l + r) / 2); // 左の子 update(a, b, x, k * 2 + 2, (l + r) / 2, r); // 右の子 dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); } } void update(int a, int b, T x) { update(a, b, x, 0, 0, n); } T query_sub(int a, int b, int k, int l, int r) { eval(k); if (r <= a || b <= l) { // 完全に外側の時 return INF; } else if (a <= l && r <= b) { // 完全に内側の時 return dat[k]; } else { // 一部区間が被る時 T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } } T query(int a, int b) { return query_sub(a, b, 0, 0, n); } /* debug */ inline T operator[](int a) { return query(a, a + 1); } void print() { for (int i = 0; i < 2 * n - 1; ++i) { cout << (*this)[i]; if (i != n) cout << ","; } cout << endl; } }; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(10); /*--------------------------------*/ ll n, a, b, c; cin >> n >> a >> b >> c; vector<string> s(n); rep(i, n) cin >> s[i]; if (a == 0 and b == 0 and c == 0) { cout << "No" << endl; return 0; } vector<char> ans; if (a + b + c == 1) { rep(i, n) { if (s[i] == "AB") { if (a == 0 and b == 0) { cout << "No" << endl; return 0; } if (a == 1) { a--; b++; ans.pb('B'); } else { b--; a++; ans.pb('A'); } } if (s[i] == "AC") { if (a == 0 and c == 0) { cout << "No" << endl; return 0; } if (a == 1) { a--; c++; ans.pb('C'); } else { c--; a++; ans.pb('A'); } } if (s[i] == "BC") { if (b == 0 and c == 0) { cout << "No" << endl; return 0; } if (b == 1) { b--; c++; ans.pb('C'); } else { c--; b++; ans.pb('B'); } } } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; return 0; } if (s[0] == "AB") { if (a == 0 and b == 0) { cout << "No" << endl; return 0; } } if (s[0] == "AC") { if (a == 0 and c == 0) { cout << "No" << endl; return 0; } } if (s[0] == "BC") { if (b == 0 and c == 0) { cout << "No" << endl; return 0; } } rep(i, n - 1) { if (s[i] == "AB" and a > 0 and b == 0) { a--; b++; ans.pb('B'); } else if (s[i] == "AB" and a == 0 and b > 0) { a++; b--; ans.pb('A'); } else if (s[i] == "AC" and (a > 0 and c == 0)) { a--; c++; ans.pb('C'); } else if (s[i] == "AC" and a == 0 and c > 0) { a++; c--; ans.pb('A'); } else if (s[i] == "BC" and (b > 0 and c == 0)) { b--; c++; ans.pb('C'); } else if (s[i] == "BC" and b == 0 and c > 0) { b++; c--; ans.pb('B'); } else if (s[i] == "AB" and s[i + 1] == "AB") { if (a >= b) { b++; a--; ans.pb('B'); } else { b--; a++; ans.pb('A'); } } else if (s[i] == "AC" and s[i + 1] == "AC") { if (a >= c) { c++; a--; ans.pb('C'); } else { c--; a++; ans.pb('A'); } } else if (s[i] == "BC" and s[i + 1] == "BC") { if (c >= b) { b++; c--; ans.pb('B'); } else { b--; c++; ans.pb('C'); } } else if (s[i] == "AC" and s[i + 1] == "AB") { a++; c--; ans.pb('A'); } else if (s[i] == "AC" and s[i + 1] == "BC") { c++; a--; ans.pb('C'); } else if (s[i] == "AB" and s[i + 1] == "AC") { a++; b--; ans.pb('A'); } else if (s[i] == "AB" and s[i + 1] == "BC") { b++; a--; ans.pb('B'); } else if (s[i] == "BC" and s[i + 1] == "AB") { b++; c--; ans.pb('B'); } else { c++; b--; ans.pb('C'); } if (a < 0 || b < 0 || c < 0) { cout << "No" << endl; return 0; } } if (s[n - 1] == "AB") { if (a > 0) ans.pb('B'); else if (b > 0) ans.pb('A'); else { cout << "No" << endl; return 0; } } if (s[n - 1] == "BC") { if (b > 0) ans.pb('C'); else if (c > 0) ans.pb('B'); else { cout << "No" << endl; return 0; } } if (s[n - 1] == "AC") { if (a > 0) ans.pb('C'); else if (c > 0) ans.pb('A'); else { cout << "No" << endl; return 0; } } cout << "Yes" << endl; rep(i, n) cout << ans[i] << endl; }
replace
550
581
550
579
-6
/usr/include/c++/12/debug/vector:442: In function: std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, _Allocator>::operator[](size_type) [with _Tp = char; _Allocator = std::allocator<char>; reference = char&; size_type = long unsigned int] Error: attempt to subscript container with out-of-bounds index 1, but container only holds 1 elements. Objects involved in the operation: sequence "this" @ 0x7ffcf34a74e0 { type = std::debug::vector<char, std::allocator<char> >; }
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<ll, ll> PLL; #define chmax(x, y) \ do { \ x = max(x, y); \ } while (0) #define chmin(x, y) \ do { \ x = min(x, y); \ } while (0) #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT template <typename T> using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>; ll N; vector<ll> a(3); vector<pair<ll, ll>> v; signed main() { cin >> N; rep(i, 3) cin >> a[i]; rep(i, N) { string s; cin >> s; v.push_back({s[0] - 'A', s[1] - 'A'}); } if (a[0] + a[1] + a[2] == 0) { // そもそもダメ cout << "No" << endl; return 0; } else if (a[0] + a[1] + a[2] <= 2) { // 何とかすればYesになるかも => DP map<vector<ll>, string> mp; // map[{0,1,1}] = "ABC" mp[a] = ""; vector<char> ans; rep(i, N) { ll x = v[i].first, y = v[i].second; map<vector<ll>, string> mp2; for (auto t : mp) { auto val = t.first; auto str = t.second; if (val[x] > 0) { vector<ll> val2 = val; string str2 = str + (string() + (char)(y + 'A')); val2[x]--; val2[y]++; mp2[val2] = str2; } if (val[y] > 0) { vector<ll> val2 = val; string str2 = str + (string() + (char)(x + 'A')); val2[x]++; val2[y]--; mp2[val2] = str2; } } if (mp2.size() == 0) { cout << "No" << endl; } swap(mp, mp2); } cout << "Yes" << endl; for (auto c : mp.begin()->second) { cout << c << endl; } } else { vector<char> ans; rep(i, N) { ll x = v[i].first, y = v[i].second; // cout << "a, b, c = " << a[0] << " " << a[1] << " " << a[2] << endl; // cout << "x, y = " << x << " " << y << endl; if (a[x] == 0 && a[y] == 0) { cout << "No" << endl; return 0; } else if (a[x] > a[y]) { a[x]--; a[y]++; ans.push_back(y + 'A'); } else { a[y]--; a[x]++; ans.push_back(x + 'A'); } } cout << "Yes" << endl; for (auto c : ans) { cout << c << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<ll, ll> PLL; #define chmax(x, y) \ do { \ x = max(x, y); \ } while (0) #define chmin(x, y) \ do { \ x = min(x, y); \ } while (0) #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) // NOLINT template <typename T> using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>; ll N; vector<ll> a(3); vector<pair<ll, ll>> v; signed main() { cin >> N; rep(i, 3) cin >> a[i]; rep(i, N) { string s; cin >> s; v.push_back({s[0] - 'A', s[1] - 'A'}); } if (a[0] + a[1] + a[2] == 0) { // そもそもダメ cout << "No" << endl; return 0; } else if (a[0] + a[1] + a[2] <= 2) { // 何とかすればYesになるかも => DP map<vector<ll>, string> mp; // map[{0,1,1}] = "ABC" mp[a] = ""; vector<char> ans; rep(i, N) { ll x = v[i].first, y = v[i].second; map<vector<ll>, string> mp2; for (auto t : mp) { auto val = t.first; auto str = t.second; if (val[x] > 0) { vector<ll> val2 = val; string str2 = str + (string() + (char)(y + 'A')); val2[x]--; val2[y]++; mp2[val2] = str2; } if (val[y] > 0) { vector<ll> val2 = val; string str2 = str + (string() + (char)(x + 'A')); val2[x]++; val2[y]--; mp2[val2] = str2; } } if (mp2.size() == 0) { cout << "No" << endl; return 0; } swap(mp, mp2); } cout << "Yes" << endl; for (auto c : mp.begin()->second) { cout << c << endl; } } else { vector<char> ans; rep(i, N) { ll x = v[i].first, y = v[i].second; // cout << "a, b, c = " << a[0] << " " << a[1] << " " << a[2] << endl; // cout << "x, y = " << x << " " << y << endl; if (a[x] == 0 && a[y] == 0) { cout << "No" << endl; return 0; } else if (a[x] > a[y]) { a[x]--; a[y]++; ans.push_back(y + 'A'); } else { a[y]--; a[x]++; ans.push_back(x + 'A'); } } cout << "Yes" << endl; for (auto c : ans) { cout << c << endl; } } return 0; }
insert
69
69
69
70
0
p02692
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (auto &x : S) cin >> x; int t = 0; if (!A || !B || !C) { vector<map<vector<int>, pair<int, int>>> a(1); a[0][{A, B, C}] = {-1, -1}; vector<int> cc; for (t = 0; t < N; ++t) { a.push_back({}); int i = S[t][0] - 'A'; int j = S[t][1] - 'A'; for (auto p : a[t]) { if (p.first[i]) { auto c = p.first; --c[i]; ++c[j]; if (!a.back().count(c)) a.back()[c] = {i, j}; if (c[0] && c[1] && c[2]) { cc = c; goto out; } } if (p.first[j]) { auto c = p.first; --c[j]; ++c[i]; if (!a.back().count(c)) a.back()[c] = {j, i}; if (c[0] && c[1] && c[2]) { cc = c; goto out; } } } if (a.back().empty()) { cout << "No" << endl; return 0; } } out:; if (cc.empty()) { cc = a[N].begin()->first; t = N + 1; } vector<int> res; for (int tt = t + 1; tt > 0; --tt) { auto ij = a[tt][cc]; res.push_back(ij.second); --cc[ij.second]; ++cc[ij.first]; } reverse(res.begin(), res.end()); cout << "Yes" << endl; for (auto i : res) cout << "ABC"[i] << endl; t = (int)res.size(); } else { cout << "Yes" << endl; } vector<int> b(3); for (; t < N; ++t) { int x = 0, y = 1; if (b[S[t][x] - 'A'] < b[S[t][y] - 'A']) swap(x, y); cout << S[t][x] << endl; --b[S[t][x] - 'A']; ++b[S[t][y] - 'A']; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, A, B, C; cin >> N >> A >> B >> C; vector<string> S(N); for (auto &x : S) cin >> x; int t = 0; if (!A || !B || !C) { vector<map<vector<int>, pair<int, int>>> a(1); a[0][{A, B, C}] = {-1, -1}; vector<int> cc; for (t = 0; t < N; ++t) { a.push_back({}); int i = S[t][0] - 'A'; int j = S[t][1] - 'A'; for (auto p : a[t]) { if (p.first[i]) { auto c = p.first; --c[i]; ++c[j]; if (!a.back().count(c)) a.back()[c] = {i, j}; if (c[0] && c[1] && c[2]) { cc = c; goto out; } } if (p.first[j]) { auto c = p.first; --c[j]; ++c[i]; if (!a.back().count(c)) a.back()[c] = {j, i}; if (c[0] && c[1] && c[2]) { cc = c; goto out; } } } if (a.back().empty()) { cout << "No" << endl; return 0; } } out:; if (cc.empty()) { cc = a[N].begin()->first; t = N - 1; } vector<int> res; for (int tt = t + 1; tt > 0; --tt) { auto ij = a[tt][cc]; res.push_back(ij.second); --cc[ij.second]; ++cc[ij.first]; } reverse(res.begin(), res.end()); cout << "Yes" << endl; for (auto i : res) cout << "ABC"[i] << endl; t = (int)res.size(); } else { cout << "Yes" << endl; } vector<int> b(3); for (; t < N; ++t) { int x = 0, y = 1; if (b[S[t][x] - 'A'] < b[S[t][y] - 'A']) swap(x, y); cout << S[t][x] << endl; --b[S[t][x] - 'A']; ++b[S[t][y] - 'A']; } }
replace
50
51
50
51
0
p02693
C++
Time Limit Exceeded
#include "bits/stdc++.h" // #include <iostream> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mem(a, v) memset((a), (v), sizeof(a)) #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define FORE(i, a, n) for (int i = (a); i <= (n); ++i) #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define anal '\n' #define mod 1000000009 typedef long long ll; int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.in", "w", stdout); #else // online submission #endif // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- int k, a, b; cin >> k >> a >> b; while (a <= b) { if (a % k == 0) { cout << "OK"; return 0; } } cout << "NG"; return 0; }
#include "bits/stdc++.h" // #include <iostream> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mem(a, v) memset((a), (v), sizeof(a)) #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define FORE(i, a, n) for (int i = (a); i <= (n); ++i) #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define anal '\n' #define mod 1000000009 typedef long long ll; int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.in", "w", stdout); #else // online submission #endif // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- int k, a, b; cin >> k >> a >> b; while (a <= b) { if (a % k == 0) { cout << "OK"; return 0; } a++; } cout << "NG"; return 0; }
insert
41
41
41
42
TLE
p02693
C++
Runtime Error
#include <iostream> using namespace std; int main() { int K, A, B; bool flag = 0; for (int i = A; i <= B; i++) { if (i % K == 0) flag = 1; } if (flag == 1) cout << "OK" << endl; else cout << "NG" << endl; }
#include <iostream> using namespace std; int main() { int K, A, B; cin >> K >> A >> B; bool flag = 0; for (int i = A; i <= B; i++) { if (i % K == 0) flag = 1; } if (flag == 1) cout << "OK" << endl; else cout << "NG" << endl; }
insert
6
6
6
7
TLE
p02693
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define fast_io() \ ; \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define loop(i, a, b) for (int i = a; i < b; i++) #define all(x) x.begin(), x.end() #define us unordered_set #define um unordered_map #define ms multiset #define mm multimap #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define mt make_tuple #define fi first #define se second #define _max max_element #define _min min_element #define tc(T) \ int T; \ cin >> T; \ while (T--) #define q(q) \ int q; \ cin >> q; \ while (q--) #define pi 3.1415926535897932384626433832 const int pinf = ((int)9e18); const int ninf = ((int)-9e18); const int mod = 1000000007; using namespace std; int32_t main() { fast_io(); // FILE *fptr1=freopen("in.txt","w",stdout); // FILE *fptr2=freopen("out.txt","w",stdout); int c, a, b; cin >> a >> b; loop(i, a, b + 1) { if (i % c == 0) { cout << "OK"; return 0; } } cout << "NG"; return 0; }
#include <bits/stdc++.h> #define int long long #define fast_io() \ ; \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define loop(i, a, b) for (int i = a; i < b; i++) #define all(x) x.begin(), x.end() #define us unordered_set #define um unordered_map #define ms multiset #define mm multimap #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define mt make_tuple #define fi first #define se second #define _max max_element #define _min min_element #define tc(T) \ int T; \ cin >> T; \ while (T--) #define q(q) \ int q; \ cin >> q; \ while (q--) #define pi 3.1415926535897932384626433832 const int pinf = ((int)9e18); const int ninf = ((int)-9e18); const int mod = 1000000007; using namespace std; int32_t main() { fast_io(); // FILE *fptr1=freopen("in.txt","w",stdout); // FILE *fptr2=freopen("out.txt","w",stdout); int c, a, b; cin >> c >> a >> b; loop(i, a, b + 1) { if (i % c == 0) { cout << "OK"; return 0; } } cout << "NG"; return 0; }
replace
45
46
45
46
0
p02693
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int K, A, B, flag = 0; cin >> A >> B; for (int i = A; i <= B; i++) { if (i % K == 0) { cout << "OK" << endl; flag = 1; break; } } if (flag != 1) { cout << "NG" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int K, A, B, flag = 0; cin >> K >> A >> B; for (int i = A; i <= B; i++) { if (i % K == 0) { cout << "OK" << endl; flag = 1; break; } } if (flag != 1) { cout << "NG" << endl; } }
replace
5
6
5
6
0
p02693
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k; cin >> a >> b; int res = (b - b % k); if (res < a) { cout << "NG"; } else cout << "OK"; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, k; cin >> k >> a >> b; int res = (b - b % k); if (res < a) { cout << "NG"; } else cout << "OK"; }
replace
6
7
6
7
0
p02693
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; vector<ll> V; int pre[maxn]; int main() { int k, a, b; cin >> a >> b; for (int i = a; i <= b; i++) { if (i % k == 0) { puts("OK"); return 0; } } puts("NG"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; vector<ll> V; int pre[maxn]; int main() { int k, a, b; cin >> k >> a >> b; for (int i = a; i <= b; i++) { if (i % k == 0) { puts("OK"); return 0; } } puts("NG"); return 0; }
replace
8
9
8
9
0
p02693
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b; cin >> k >> a >> b; bool f = 0; for (int i = a; a <= b; i++) if (i % k == 0) f = 1; cout << (f ? "OK" : "NG") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b; cin >> k >> a >> b; bool f = 0; for (int i = a; i <= b; i++) if (i % k == 0) f = 1; cout << (f ? "OK" : "NG") << endl; }
replace
6
7
6
7
TLE
p02693
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int K, A, B; cin >> K >> A >> B; while (true) { bool add = false; for (int i = 0; i < 100; i++) { if (A <= K * i && B >= K * i) { add = true; } } if (add) { cout << "OK" << endl; } else { cout << "NG" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b; cin >> k >> a >> b; if (a <= (b / k) * k) { cout << "OK" << endl; } else { cout << "NG" << endl; } }
replace
4
18
4
10
TLE
p02693
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long int ll; #define pb push_back typedef pair<ll, ll> pp; ll mod = 1e9 + 7; ll INF = 1e15; ll powm(ll a, ll b, ll mod) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >> 1; } return res; } ll gcd(ll a, ll b); ll power(ll x, ll y, ll m); ll modInverse(ll a, ll m) { ll g = gcd(a, m); if (g != 1) return 1; else return power(a, m - 2, m); } ll power(ll x, ll y, ll m) { if (y == 0) return 1; ll p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } void solve() { int k, a, b, flag = 0; for (int i = a; i <= b; i++) { if (i % k == 0) flag = 1; } if (flag) cout << "OK\n"; else cout << "NG\n"; } int main() { int tc; // cin>>tc; tc = 1; while (tc--) { solve(); } }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long int ll; #define pb push_back typedef pair<ll, ll> pp; ll mod = 1e9 + 7; ll INF = 1e15; ll powm(ll a, ll b, ll mod) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >> 1; } return res; } ll gcd(ll a, ll b); ll power(ll x, ll y, ll m); ll modInverse(ll a, ll m) { ll g = gcd(a, m); if (g != 1) return 1; else return power(a, m - 2, m); } ll power(ll x, ll y, ll m) { if (y == 0) return 1; ll p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } void solve() { int k, a, b, flag = 0; cin >> k >> a >> b; for (int i = a; i <= b; i++) { if (i % k == 0) flag = 1; } if (flag) cout << "OK\n"; else cout << "NG\n"; } int main() { int tc; // cin>>tc; tc = 1; while (tc--) { solve(); } }
insert
49
49
49
50
TLE
p02693
Python
Runtime Error
K = int(input()) A, B = map(int, input().slice()) print("OK" if B - A >= K else "NG")
K = int(input()) A, B = map(int, input().split()) large = (B // K) * K if A <= large: print("OK") else: print("NG")
replace
1
3
1
7
AttributeError: 'str' object has no attribute 'slice'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02693/Python/s877795440.py", line 2, in <module> A, B = map(int, input().slice()) AttributeError: 'str' object has no attribute 'slice'
p02693
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define mp make_pair #define pb push_back #define pii pair<int, int> #define link(x) for (edge *j = h[x]; j; j = j->next) #define inc(i, l, r) for (int i = l; i <= r; i++) #define dec(i, r, l) for (int i = r; i >= l; i--) const int MAXN = 3e5 + 10; const double eps = 1e-8; const int mod = 1e9 + 9; #define ll long long using namespace std; struct edge { int t, v; edge *next; } e[MAXN << 1], *h[MAXN], *o = e; void add(int x, int y, int vul) { o->t = y; o->v = vul; o->next = h[x]; h[x] = o++; } ll read() { ll x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } int k, a, b; int main() { k = read(); a = read(); b = read(); int x = b / k * k; if (x >= a) return puts("OK"); else puts("NG"); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define mp make_pair #define pb push_back #define pii pair<int, int> #define link(x) for (edge *j = h[x]; j; j = j->next) #define inc(i, l, r) for (int i = l; i <= r; i++) #define dec(i, r, l) for (int i = r; i >= l; i--) const int MAXN = 3e5 + 10; const double eps = 1e-8; const int mod = 1e9 + 9; #define ll long long using namespace std; struct edge { int t, v; edge *next; } e[MAXN << 1], *h[MAXN], *o = e; void add(int x, int y, int vul) { o->t = y; o->v = vul; o->next = h[x]; h[x] = o++; } ll read() { ll x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * f; } int k, a, b; int main() { k = read(); a = read(); b = read(); int x = b / k * k; if (x >= a) puts("OK"); else puts("NG"); return 0; }
replace
51
52
51
52
3
p02693
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int k; int a[1]; cin >> k; for (int i = 0; i < 2; i++) { cin >> a[i]; } if (a[1] - a[0] >= k - 1) { cout << "OK" << endl; } else { cout << "NG" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int k, a, b; cin >> k >> a >> b; int i = b / k; if (k * i >= a) { cout << "OK" << endl; } else { cout << "NG" << endl; } return 0; }
replace
4
11
4
8
-6
*** stack smashing detected ***: terminated
p02693
C++
Runtime Error
#include "bits/stdc++.h" #define EPS 1e-9 using namespace std; const int N = 1e5, OO = 0x3f3f3f3f; typedef long long ll; int main() { int a, b, k; for (int i = min(a, b); i <= max(a, b); i++) if (i % k == 0) return cout << "OK", 0; cout << "NG"; }
#include "bits/stdc++.h" #define EPS 1e-9 using namespace std; const int N = 1e5, OO = 0x3f3f3f3f; typedef long long ll; int main() { int a, b, k; cin >> k >> a >> b; for (int i = a; i <= b; i++) if (i % k == 0) return cout << "OK", 0; cout << "NG"; }
replace
7
8
7
9
0
p02693
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k, a, b; cin >> k >> a >> b; for (ll i = a; i = b; ++i) { if (i % k == 0) { cout << "OK" << endl; return 0; } } cout << "NG" << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k, a, b; cin >> k >> a >> b; for (ll i = a; i <= b; ++i) { if (i % k == 0) { cout << "OK" << endl; return 0; } } cout << "NG" << endl; }
replace
7
8
7
8
TLE
p02693
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18, MOD = 1e9 + 7; const int INT_INF = 1e9, INT_MOD = 1e9 + 7; #define rep(i, N) for (int i = 0; i < N; i++) typedef pair<int, int> Pi; typedef pair<double, double> P; signed main() { int k, a, b; cin >> k >> a >> b; for (int i = a; i <= b; i++) { if (i %= k == 0) { cout << "OK" << endl; return 0; } } cout << "NG" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18, MOD = 1e9 + 7; const int INT_INF = 1e9, INT_MOD = 1e9 + 7; #define rep(i, N) for (int i = 0; i < N; i++) typedef pair<int, int> Pi; typedef pair<double, double> P; signed main() { int k, a, b; cin >> k >> a >> b; for (int i = a; i <= b; i++) { if (i % k == 0) { cout << "OK" << endl; return 0; } } cout << "NG" << endl; return 0; }
replace
12
13
12
13
TLE
p02693
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, s, n) for (int i = (int)s; i < (int)n; i++) #define in(i) std::cin >> i; #define print(i) std::cout << i; #define println(i) std::cout << i << std::endl; using namespace std; int main() { int k, a, b, i = 0; string ans = "NG"; cin >> k >> a >> b; while (1) { if (k * i >= a && k * i <= b) { ans = "OK"; break; } else if (k * i > b) { break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, s, n) for (int i = (int)s; i < (int)n; i++) #define in(i) std::cin >> i; #define print(i) std::cout << i; #define println(i) std::cout << i << std::endl; using namespace std; int main() { int k, a, b, i = 0; string ans = "NG"; cin >> k >> a >> b; while (1) { if (k * i >= a && k * i <= b) { ans = "OK"; break; } else if (k * i > b) { break; } i++; } cout << ans << endl; return 0; }
insert
25
25
25
26
TLE
p02693
C++
Runtime Error
#include <iostream> using namespace std; int countDivisibles(int A, int B, int M) { bool check = false; for (int i = A; i <= B; i++) { if (i % M == 0) check = true; } if (check) cout << "OK" << endl; else { cout << "NG" << endl; } } int main() { int A, B, M; cin >> M; cin >> A >> B; countDivisibles(A, B, M); return 0; }
#include <iostream> using namespace std; void countDivisibles(int A, int B, int M) { bool check = false; for (int i = A; i <= B; i++) { if (i % M == 0) check = true; } if (check) cout << "OK" << endl; else { cout << "NG" << endl; } } int main() { int A, B, M; cin >> M; cin >> A >> B; countDivisibles(A, B, M); return 0; }
replace
3
4
3
4
0
p02693
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define irep(i, a, b) for (typeof(i) i = (a); i < (b); ++i) #define itrep(it, c) for (auto it = (c).begin(); it != (c).end(); ++it) int main() { ios::sync_with_stdio(false); cin.tie(NULL); ll K, A, B; cin >> K >> A >> B; for (ll i = A; i <= B; i++) { if (i % K == 0) { cout << "OK" << endl; return 1; } } cout << "NG" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define irep(i, a, b) for (typeof(i) i = (a); i < (b); ++i) #define itrep(it, c) for (auto it = (c).begin(); it != (c).end(); ++it) int main() { ios::sync_with_stdio(false); cin.tie(NULL); ll K, A, B; cin >> K >> A >> B; for (ll i = A; i <= B; i++) { if (i % K == 0) { cout << "OK" << endl; return 0; } } cout << "NG" << endl; }
replace
17
18
17
18
1
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int X; int Y = 100; int C = 0; cin >> X; while (Y < X) { Y += Y / 100; C++; } cout << (C) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long X; long Y = 100; long C = 0; cin >> X; while (Y < X) { Y += Y / 100; C++; } cout << (C) << endl; }
replace
5
8
5
8
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG int main() { using vi = vector<int>; int a = 100; int count = 0; int x; cin >> x; while (a < x) { count++; a *= 1.01; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG int main() { using vi = vector<int>; long long a = 100; long long count = 0; long long x; cin >> x; while (a < x) { count++; a *= 1.01; } cout << count << endl; }
replace
9
12
9
12
TLE
p02694
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> // #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++) typedef long long ll; int main() { ll x; cin >> x; ll deposit = 100; ll year = 0; while (true) { deposit += deposit / 100 % 10; year++; if (deposit >= x) break; } cout << year << endl; return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> // #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++) typedef long long ll; int main() { ll x; cin >> x; ll deposit = 100; ll year = 0; while (true) { deposit += deposit / 100; year++; if (deposit >= x) break; } cout << year << endl; return 0; }
replace
19
20
19
20
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; int sum = 0; int mon = 100; while (mon < X) { mon += mon / 100; sum++; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long X; cin >> X; int sum = 0; long long mon = 100; while (mon < X) { mon += mon / 100; sum++; } cout << sum << endl; }
replace
7
8
7
8
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, a = 100, i = 0; cin >> x; for (; a < x; i += 1) { a *= 1.01; } cout << i << endl; return 0; }
#include <iostream> using namespace std; int main() { long long x, a = 100, i = 0; cin >> x; for (; a < x; i += 1) { a *= 1.01; } cout << i << endl; return 0; }
replace
4
5
4
5
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long money = 100; int i; for (i = 0; money < x; i++) { money = money * 101 / 100; } cout << i << endl; }
#include <iostream> using namespace std; int main() { long long x; cin >> x; long long money = 100; int i; for (i = 0; money < x; i++) { money = money + money / 100; } cout << i << endl; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll X; cin >> X; int r = 100; ll ans = 0; while (r < X) { r = r * 1.01; ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll X; cin >> X; ll r = 100; ll ans = 0; while (r < X) { r = r * 1.01; ans++; } cout << ans << endl; }
replace
7
8
7
8
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, y = 100, i = 0; cin >> x; for (; y < x; i++) { y *= 1.01; } cout << i; }
#include <iostream> using namespace std; int main() { long long x, y = 100, i = 0; cin >> x; for (; y < x; i++) { y *= 1.01; } cout << i; }
replace
3
4
3
4
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(array[0]) int main() { long long X; cin >> X; int year = 0; for (int i = 100; i < X;) { i *= 1.01; year++; } cout << year; }
#include <bits/stdc++.h> using namespace std; #define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(array[0]) int main() { long long X; cin >> X; long long year = 0; for (long long i = 100; i < X;) { i += i * 0.01; year++; } cout << year; }
replace
8
11
8
11
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long X, deposit; cin >> X; long i = 0; deposit = 1; while (deposit < X) { deposit *= 1.01; i++; } cout << i << endl; return 0; }
#include <iostream> using namespace std; int main() { long X, deposit; cin >> X; long i = 0; deposit = 100; while (deposit < X) { deposit *= 1.01; i++; } cout << i << endl; return 0; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int x, i, sum; i = 0; sum = 100; cin >> x; while (sum < x) { sum = sum * 1.01; i++; } cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long x, i, sum; i = 0; sum = 100; cin >> x; while (sum < x) { sum = sum * 1.01; i++; } cout << i << endl; return 0; }
replace
4
5
4
5
TLE
p02694
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define fi first #define se second const int N = 3e5 + 6; const int mod = 1e9 + 7; const int inf = 1e8; void solve() { ll k; cin >> k; ll st = 100; for (int i = 0; i <= 40000; i++) { if (st >= k) { cout << i << endl; break; } ll interst = st * 0.01; st += interst; } exit(-1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define fi first #define se second const int N = 3e5 + 6; const int mod = 1e9 + 7; const int inf = 1e8; void solve() { ll k; cin >> k; ll st = 100; for (int i = 0; i <= 40000; i++) { if (st >= k) { cout << i << endl; return; } ll interst = st * 0.01; st += interst; } exit(-1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
replace
17
18
17
18
255
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; int t = 0; long long k = 100; while (k != a) { k = k * 1.01; t++; } cout << t; }
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; int t = 0; long long k = 100; while (k < a) { k = k * 1.01; t++; } cout << t; }
replace
8
9
8
9
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { int InVal = 100; int x; int years = 0; cin >> x; while (InVal < x) { InVal = floor(InVal * 1.01); ++years; } cout << years << endl; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { long long InVal = 100; long long x; long long years = 0; cin >> x; while (InVal < x) { InVal = floor(InVal * 1.01); ++years; } cout << years << endl; return 0; }
replace
5
8
5
8
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int money = 100; int X; cin >> X; int year = 0; while (money < X) { money = money + money / 100; year++; } cout << year << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long money = 100; long long X; cin >> X; int year = 0; while (money < X) { money = money + money / 100; year++; } cout << year << endl; }
replace
4
6
4
6
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { double x; int i, a = 100; cin >> x; for (i = 0; a < x; i++) { a = a * 1.01; } cout << i << endl; }
#include <iostream> using namespace std; int main() { double x; long i, a = 100; cin >> x; for (i = 0; a < x; i++) { a = a * 1.01; } cout << i << endl; }
replace
5
6
5
6
TLE
p02694
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <string> #define START 100 using namespace std; int main() { int year, money, value; long x; cin >> x; money = START; year = 0; while (money < x) { value = money / 100; money += value; year++; } cout << year; }
#include <cmath> #include <iostream> #include <string> #define START 100 using namespace std; int main() { int year; long x, money, value; cin >> x; money = START; year = 0; while (money < x) { value = money / 100; money += value; year++; } cout << year; }
replace
9
11
9
11
TLE
p02694
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <ctype.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readc(c) \ char c; \ cin >> c; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define loopchar() for (char c = 'a'; c <= 'z'; c++) #define printarr(a, n) \ fori(i, 1, n) cout << a[i] << " "; \ cout << endl; #define printv(v) \ for (int i : v) \ cout << i << " "; \ cout << endl; #define loopitr(vec) for (auto itr = vec.begin(); itr != vec.end(); itr++) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define all(a) a.begin(), a.end() #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define sc(x) cout << (#x) << " is " << (x) << endl; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #define fsort(vec) sort(vec.begin(), vec.end()) #define rsort(vec) sort(vec.begin(), vec.end(), compare) #define Endl endl #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define roundoff std::cout << std::setprecision(15) #define inf 9223372036854775807 #define infn -9223372036854775807 #define pi 3.14159265358979323846 const int mod = 1e9 + 7; #define intsize ll size = trunc(log10(num)) + 1 #define REVERSE(vec) reverse(vec.begin(), vec.end()) using namespace __gnu_pbds; using namespace std; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // code start from here int main() { fast; read(x) ll sum = 100; ll a = 100; ll t = 0; while (a < x) { a = a * 101; a = a / 100; t++; } cout << t; return 0; } // ends here
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <ctype.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readc(c) \ char c; \ cin >> c; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define loopchar() for (char c = 'a'; c <= 'z'; c++) #define printarr(a, n) \ fori(i, 1, n) cout << a[i] << " "; \ cout << endl; #define printv(v) \ for (int i : v) \ cout << i << " "; \ cout << endl; #define loopitr(vec) for (auto itr = vec.begin(); itr != vec.end(); itr++) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define all(a) a.begin(), a.end() #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define sc(x) cout << (#x) << " is " << (x) << endl; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #define fsort(vec) sort(vec.begin(), vec.end()) #define rsort(vec) sort(vec.begin(), vec.end(), compare) #define Endl endl #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define roundoff std::cout << std::setprecision(15) #define inf 9223372036854775807 #define infn -9223372036854775807 #define pi 3.14159265358979323846 const int mod = 1e9 + 7; #define intsize ll size = trunc(log10(num)) + 1 #define REVERSE(vec) reverse(vec.begin(), vec.end()) using namespace __gnu_pbds; using namespace std; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // code start from here int main() { fast; read(x) ll sum = 100; ll a = 100; ll t = 0; while (a < x) { a = a * 1.01; t++; } cout << t; return 0; } // ends here
replace
81
83
81
82
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pp pop_back #define in insert #define ff first #define ss second #define e endl #define MAXN 2005 #define MOD 998244353 int main() { ll x; cin >> x; ll a = 100; ll t = 0; while (a < x) { a = a * 101; a = a / 100; t++; } cout << t; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pp pop_back #define in insert #define ff first #define ss second #define e endl #define MAXN 2005 #define MOD 998244353 int main() { ll x; cin >> x; ll a = 100; ll t = 0; while (a < x && t <= 4000) { a *= 1.01; t++; } cout << t; }
replace
19
23
19
21
TLE
p02694
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { // prepare variables int init_value = 100; long int target_value; cin >> target_value; // calculate answer int ans = 0; long int stock = init_value; while (ans <= 1e18) { stock = (int)(stock * 1.01); ans++; if (stock >= target_value) { break; } } cout << ans << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { // prepare variables int init_value = 100; long int target_value; cin >> target_value; // calculate answer int ans = 0; long int stock = init_value; while (ans <= 1e18) { stock = (long int)(stock * 1.01); ans++; if (stock >= target_value) { break; } } cout << ans << endl; return 0; }
replace
14
15
14
15
TLE
p02694
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; int main() { long long X; long long ans = 100; int i = 0; cin >> X; while (ans < X) { ans *= 101; ans /= 100; i++; } cout << i; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; int main() { long long X; long long ans = 100; int i = 0; cin >> X; while (ans < X) { ans += ans / 100; i++; } cout << i; }
replace
17
19
17
18
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long x, y = 100, cnt = 0; cin >> x; while (true) { if (x <= y) { cout << cnt << endl; return 0; } cnt++; y = y * 20.1 / 20; } }
#include <bits/stdc++.h> using namespace std; int main() { long long x, y = 100, cnt = 0; cin >> x; while (true) { if (x <= y) { cout << cnt << endl; return 0; } cnt++; y = y + y / 100; } }
replace
13
14
13
14
TLE
p02694
C++
Time Limit Exceeded
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") // #pragma GCC optimize ("Ofast,no-stack-protector") // #pragma GCC optimize ("unroll-loops") // #pragma GCC optimize ("fast-math") // #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned long long ull; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pll; typedef vector<pll> vpll; #define ff first #define ss second #define pb push_back #define mp make_pair #define eb emplace_back #define fr(i, n) for (ll i = 0; i < n; ++i) #define frs(i, s, n) for (ll i = s; i < n; ++i) #define frb(i, s, e) for (ll i = s; i <= e; ++i) #define rfr(i, n) for (ll i = n - 1; i >= 0; i--) #define frbr(i, e, s) for (ll i = e; i >= s; i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) inline void __print(int x) { cerr << x; } inline void __print(long x) { cerr << x; } inline void __print(long long x) { cerr << x; } inline void __print(unsigned x) { cerr << x; } inline void __print(unsigned long x) { cerr << x; } inline void __print(unsigned long long x) { cerr << x; } inline void __print(float x) { cerr << x; } inline void __print(double x) { cerr << x; } inline void __print(long double x) { cerr << x; } inline void __print(char x) { cerr << '\'' << x << '\''; } inline void __print(const char *x) { cerr << '\"' << x << '\"'; } inline void __print(const string &x) { cerr << '\"' << x << '\"'; } inline void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> inline void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> inline void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } inline void _print() { cerr << "]\n"; } template <typename T, typename... V> inline void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } clock_t startTime; inline double getCurrentTime() { return ((double)(clock() - startTime)) / CLOCKS_PER_SEC; } #ifdef LOCAL #define dbg(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #define dbg_arr(a, n) \ cerr << "[" << #a << "] = [ "; \ fr(i, n) cerr << a[i] << " "; \ cerr << "]\n"; #define dbg_mat(m, r, c) \ cerr << "[" << #m << "]:\n"; \ fr(i, r) { \ cerr << "[ "; \ fr(j, c) cerr << m[i][j] << " "; \ cerr << "]\n"; \ } #define dbg_time() cerr << endl << "Time elapsed: " << getCurrentTime() << endl; #define tle() \ { \ if (getCurrentTime() > 5.0) { \ dbg_time(); \ cerr << "[-INF-Exit-]" << endl; \ exit(1); \ } \ } #else #define dbg(x...) \ {} #define dbg_arr(a, n) \ {} #define dbg_mat(m, r, c) \ {} #define dbg_time() \ {} #define tle() \ {} #endif const ld PI = 3.14159265359; const ld EPS = 1e-9; const ll MOD = 1e9 + 7; const ll SMOD = 998244353; const ll INF = 1e18; const ll SINF = 1e9; const ll MAX = 100100; void pre() { // factorial(); } void solve() { ll x; cin >> x; ll p = 100; ll ans = 0; while (1) { if (p >= x) { dbg(x, p); cout << ans << '\n'; return; } p = (p * 101) / 100; ans++; } } signed main() { startTime = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // cout << fixed << setprecision(15); pre(); ll test = 1; // cin >> test; fr(ii, test) { // cout << "Case #" << ii + 1 << ": "; solve(); } dbg_time(); return 0; }
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") // #pragma GCC optimize ("Ofast,no-stack-protector") // #pragma GCC optimize ("unroll-loops") // #pragma GCC optimize ("fast-math") // #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned long long ull; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<ll, ll> pll; typedef vector<pll> vpll; #define ff first #define ss second #define pb push_back #define mp make_pair #define eb emplace_back #define fr(i, n) for (ll i = 0; i < n; ++i) #define frs(i, s, n) for (ll i = s; i < n; ++i) #define frb(i, s, e) for (ll i = s; i <= e; ++i) #define rfr(i, n) for (ll i = n - 1; i >= 0; i--) #define frbr(i, e, s) for (ll i = e; i >= s; i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) inline void __print(int x) { cerr << x; } inline void __print(long x) { cerr << x; } inline void __print(long long x) { cerr << x; } inline void __print(unsigned x) { cerr << x; } inline void __print(unsigned long x) { cerr << x; } inline void __print(unsigned long long x) { cerr << x; } inline void __print(float x) { cerr << x; } inline void __print(double x) { cerr << x; } inline void __print(long double x) { cerr << x; } inline void __print(char x) { cerr << '\'' << x << '\''; } inline void __print(const char *x) { cerr << '\"' << x << '\"'; } inline void __print(const string &x) { cerr << '\"' << x << '\"'; } inline void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> inline void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> inline void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } inline void _print() { cerr << "]\n"; } template <typename T, typename... V> inline void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } clock_t startTime; inline double getCurrentTime() { return ((double)(clock() - startTime)) / CLOCKS_PER_SEC; } #ifdef LOCAL #define dbg(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #define dbg_arr(a, n) \ cerr << "[" << #a << "] = [ "; \ fr(i, n) cerr << a[i] << " "; \ cerr << "]\n"; #define dbg_mat(m, r, c) \ cerr << "[" << #m << "]:\n"; \ fr(i, r) { \ cerr << "[ "; \ fr(j, c) cerr << m[i][j] << " "; \ cerr << "]\n"; \ } #define dbg_time() cerr << endl << "Time elapsed: " << getCurrentTime() << endl; #define tle() \ { \ if (getCurrentTime() > 5.0) { \ dbg_time(); \ cerr << "[-INF-Exit-]" << endl; \ exit(1); \ } \ } #else #define dbg(x...) \ {} #define dbg_arr(a, n) \ {} #define dbg_mat(m, r, c) \ {} #define dbg_time() \ {} #define tle() \ {} #endif const ld PI = 3.14159265359; const ld EPS = 1e-9; const ll MOD = 1e9 + 7; const ll SMOD = 998244353; const ll INF = 1e18; const ll SINF = 1e9; const ll MAX = 100100; void pre() { // factorial(); } void solve() { ll x; cin >> x; ll p = 100; ll ans = 0; while (1) { if (p >= x) { dbg(x, p); cout << ans << '\n'; return; } p = (ll)(ld(p) * ld(1.01)); ans++; } } signed main() { startTime = clock(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // cout << fixed << setprecision(15); pre(); ll test = 1; // cin >> test; fr(ii, test) { // cout << "Case #" << ii + 1 << ": "; solve(); } dbg_time(); return 0; }
replace
131
132
131
132
TLE
p02694
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long s = 100; int res = 0; while (s < x) { s = s + s * 0.01; res++; } cout << res; return res; }
#include <bits/stdc++.h> using namespace std; int main() { long long x; cin >> x; long long s = 100; int res = 0; while (s < x) { s = s + s * 0.01; res++; } cout << res; return 0; }
replace
13
14
13
14
3
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, n) for (int i = a; i < n; i++) using namespace std; long long X; int main() { cin >> X; long long res = 0; long long money = 100; while (money < X) { money = money * 101 / 100; res++; } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, n) for (int i = a; i < n; i++) using namespace std; long long X; int main() { cin >> X; long long res = 0; long long money = 100; while (money < X) { money = money * 1.01; res++; } cout << res << endl; return 0; }
replace
10
11
10
11
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int a = 100; long long x; cin >> x; int i = 0; while (a < x) { a += a / 100; i++; } cout << i << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long a = 100; long long x; cin >> x; int i = 0; while (a < x) { a += a / 100; i++; } cout << i << endl; }
replace
4
5
4
5
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, i; b = 100; i = 0; cin >> a; while (b < a) { b = (b * 101) / 100; i++; } cout << i; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, i; b = 100; i = 0; cin >> a; while (b < a) { long long c = b / 100; b = b + c; i++; } cout << i; }
replace
8
9
8
10
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x; cin >> x; ll ans = 0; ll y = 100; while (y < x) { y = y * 101 / 100; // cout << y << endl; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x; cin >> x; ll ans = 0; ll y = 100; while (y < x) { y += y / 100; // cout << y << endl; ans++; } cout << ans << endl; return 0; }
replace
12
13
12
13
TLE
p02694
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int x, d = 100, y = 0; cin >> x; while (d < x) { d = d * 1.01; y++; } cout << y << endl; return 0; }
#include <iostream> using namespace std; int main() { long x, d = 100, y = 0; cin >> x; while (d < x) { d = d * 1.01; y++; } cout << y << endl; return 0; }
replace
5
6
5
6
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { long long X; cin >> X; long long ykn = 100; int ans = 0; while (ykn < X) { ans++; ykn = ykn * 101 / 100; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { long long X; cin >> X; long long ykn = 100; int ans = 0; while (ykn < X) { ans++; ykn += ykn / 100; } cout << ans << endl; return 0; }
replace
13
14
13
14
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long a, cnt = 100; cin >> a; for (int i = 0;; i++) { cnt = cnt + cnt / 100; if (cnt == a) { cout << i + 1; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, cnt = 100; cin >> a; for (int i = 0;; i++) { cnt = cnt + cnt / 100; if (cnt >= a) { cout << i + 1; return 0; } } return 0; }
replace
7
8
7
8
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, m = 100, ans = 0; cin >> x; while (true) { m = m * 101 / 100; ++ans; if (m >= x) break; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll x, m = 100, ans = 0; cin >> x; while (true) { m = m * 1.01; ++ans; if (m >= x) break; } cout << ans << endl; }
replace
11
12
11
12
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long #define big 998244353 #define ff first #define se second #define pb push_back #define pii pair<int, int> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define mp make_pair #define pi 3.141592653589 int power(int x, int y) { int r = 1, z = x; while (y) { if (y & 1) r *= z; z *= z; y = y >> 1; } return r; } int powerm(int x, int y, int p) { int r = 1; while (y) { if (y & 1) r = (r * x) % p; y = y >> 1; x = (x * x) % p; } return r % p; } int modinv(int x, int m) { return powerm(x, m - 2, m); } int logarithm(int a, int b) { int x = 0; while (a > 1) { x++; a /= b; } return x; } int32_t main() { fast; int x; cin >> x; int curr = 100; int t = 0; while (curr < x) { t++; curr = curr * 101 / 100; } cout << t; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long #define big 998244353 #define ff first #define se second #define pb push_back #define pii pair<int, int> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define mp make_pair #define pi 3.141592653589 int power(int x, int y) { int r = 1, z = x; while (y) { if (y & 1) r *= z; z *= z; y = y >> 1; } return r; } int powerm(int x, int y, int p) { int r = 1; while (y) { if (y & 1) r = (r * x) % p; y = y >> 1; x = (x * x) % p; } return r % p; } int modinv(int x, int m) { return powerm(x, m - 2, m); } int logarithm(int a, int b) { int x = 0; while (a > 1) { x++; a /= b; } return x; } int32_t main() { fast; int x; cin >> x; int curr = 100; int t = 0; while (curr < x) { t++; curr = curr * 1.01; } cout << t; return 0; }
replace
53
54
53
54
TLE
p02694
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define FOR(i, l, r) for (i = l; i < r; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define P pair<ll, ll> #define F first #define S second signed main() { ll X, i = 100, ans = 0; cin >> X; while (i < X) { ans++; i = i * 101 / 100; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define FOR(i, l, r) for (i = l; i < r; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define P pair<ll, ll> #define F first #define S second signed main() { ll X, i = 100, ans = 0; cin >> X; while (i < X) { ans++; i += i / 100; } cout << ans << endl; return 0; }
replace
25
26
25
26
TLE