# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476181 | Moeriko_chan | Igra (COCI17_igra) | C++14 | 1 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
//add more if needed-------------------------------------------------//
#define fio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rfopen(s) freopen(s, "r", stdin)
#define wfopen(s) freopen(s, "w", stdout)
#define len(a) int(a.size())
#define forw(i, a, b, s) for(int i = a; i < b; i += s)
#define revs(i, a, b, s) for(int i = a; i > b; i -= s)
#define PB push_back
#define EB emplace_back
#define ever ;;
#define FS first
#define SC second
#define PI acos(-1.0)
#define resarr(a) memset(a, 0, sizeof a);
#define allv(v) v.begin(), v.end()
//bit
#define CNTBIT(x) __builtin_popcount(x)
#define ODDBIT(x) __builtin_parity(x)
#define MASK(i) (1<<(i))
#define BIT(x, i) x&MASK(i)
#define SUBSET(big, small) (((big)&(small))==(small))
using namespace std;
namespace io {
const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
inline void flush() { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; } // print the remaining part
inline void putc(char x) { *oS++ = x; if (oS == oT) flush (); } // putchar
template<typename A> inline bool read (A &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1; else if (c == EOF) return 0;
for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
return 1;
}
inline bool read(char &x) {
while((x = gc()) == ' ' || x == '\n' || x == '\r'); return x != EOF;
}
inline bool read(string& x) {
while ((c = gc()) == '\n' || c == ' '|| c == '\r'); if (c == EOF) return 0; x.clear();
while (!(c == '\n' || c == ' ' || c == '\r' || c == EOF)) x.push_back(c), c = gc(); return 1;
}
template<typename A,typename ...B>
inline bool read(A &x, B &...y){ return read(x) + read(y...); }
template<typename A> inline bool write(A x) {
if (!x) putc('0'); if (x < 0) putc ('-'), x = -x;
while (x) qu[++qr] = x % 10 + '0', x /= 10;
while (qr) putc(qu[qr--]);
return 0;
}
inline bool write(char x) { putc(x); return 0; }
inline bool write(const char *x){ while (*x){ putc(*x); ++x; } return 0; }
inline bool write(char *x){ while (*x){ putc(*x); ++x; } return 0; }
template<typename A,typename ...B>
inline bool write(A x,B ...y){ return write(x) || write(y...); }
//no need to call flush at the end manually!
struct Flusher_ {~Flusher_(){ flush(); }} io_flusher_;
} using io::read; using io::putc; using io::write;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<ll, ll> pll;
typedef pair<pii, int> pii_i;
typedef pair<int, pii> pi_ii;
typedef pair<int, pll> pi_ll;
typedef pair<float, int> pfi;
typedef pair<ull, pii> pull_ii;
typedef pair<float, pii> pfii;
int divceil(int x, int y){
return 1 + ((x - 1) / y);
}
//add more if needed-------------------------------------------------//
const int INF = 1e9 + 7;
const ll INF64 = 1e18 + 7;
const float fINF = 340282346638528859811704183484516925439.0000000000000000;
const int N = 5007; ///replace N with the given limit
const int MOD = 1e9 + 7; ///replace this with mod value
int l;
char cr[N];
int ctr[2][3];
char ans[N];
bool kt(int ch){
int val[3] = {ctr[0][0], ctr[0][1], ctr[0][2]};
val[ch]--;
if (val[ch] < 0) return false;
if (val[0] + val[2] >= ctr[1][1] && val[0] <= ctr[1][1] + ctr[1][2] && val[2] <= ctr[1][0] + ctr[1][1])
return true;
return false;
}
int main(){
///preprocessing
#ifndef ONLINE_JUDGE
//rfopen("test.inp");
//wfopen("test.out");
#endif // ONLINE_JUDGE
fio;
///codes:
cin >> l;
for (int i = 0; i < l; i++){
char r;
cin >> r;
ctr[0][r - 'a']++;
}
for (int i = 0; i < l; i++){
cin >> cr[i];
ctr[1][cr[i] - 'a']++;
}
for (int i = 0; i < l; i++){
ctr[1][cr[i] - 'a']--;
for (int j = 0; j < 3; j++){
if (cr[i] - 'a' != j && kt(j)){
ctr[0][j]--;
ans[i] = char(j + 'a');
break;
}
}
}
for (int i = 0; i < l; i++){
cout << ans[i];
}
}
/**
Must read note before coding ANYTHING!!!:
- Plan things out before coding (variable names, function names and such) and stay organized
- Put things that have to be use multiple times into a function
- Simplify shit as much as possible (still have to be readable)
- Do something instead of nothing
- Use note
- DO NOT STICK TO ONE APPROACH!!!
Stuff you should look for while debugging:
- int overflow
- array bound
- special cases (n == 1), (n == 0)?
Read these before doing anything, you"ll thanks me later >^<
~(Ruriko, from the Past)~
**/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |