QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#23780 | #2967. Snowball Fight | FudanU1# | AC ✓ | 4ms | 3744kb | C++20 | 5.1kb | 2022-03-19 14:17:22 | 2022-04-30 04:07:44 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define srep(i, l, r) for (int i = l; i < r; i++)
#define sper(i, r, l) for (int i = r; i > l; i--)
#define erep(i, x) for (int i = h[x]; i; i = e[i].next)
#define erep2(i, x) for (int& i = cur[x]; i; i = e[i].next)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define fi first
#define se second
#define ui unsigned int
#define ld long double
#define pb push_back
#define pc putchar
#define lowbit(x) (x & -x)
#define maxbuf 2000020
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxbuf, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;
namespace Fast_Read{
char buffer[maxbuf], *p1, *p2;
template<class T> void read_signed(T& x){
char ch = gc(); x = 0; bool f = 1;
while (!isdigit(ch) && ch != '-') ch = gc();
if (ch == '-') f = 0, ch = gc();
while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
x = (f) ? x : -x;
}
template<class T, class... Args> void read_signed(T& x, Args&... args){
read_signed(x), read_signed(args...);
}
template<class T> void read_unsigned(T& x){
char ch = gc(); x = 0;
while (!isdigit(ch)) ch = gc();
while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = gc();
}
template<class T, class... Args> void read_unsigned(T& x, Args&... args){
read_unsigned(x), read_unsigned(args...);
}
#define isletter(ch) ('a' <= ch && ch <= 'z')
int read_string(char* s){
char ch = gc(); int l = 0;
while (!isletter(ch)) ch = gc();
while (isletter(ch)) s[l++] = ch, ch = gc();
s[l] = '\0'; return l;
}
}using namespace Fast_Read;
int _num[20];
template <class T> void write(T x, char sep = '\n'){
if (!x) {putchar('0'), putchar(sep); return;}
if (x < 0) putchar('-'), x = -x;
int c = 0;
while (x) _num[++c] = x % 10, x /= 10;
while (c) putchar('0' + _num[c--]);
putchar(sep);
}
#define read read_signed
#define reads read_string
#define writes puts
#define maxn
#define maxm
#define maxs
#define maxb
#define inf
#define eps
#define M
#define ll long long int
#define plc pair<ll, char>
char left(char x) {
if (x == 'A') return 'B';
if (x == 'B') return 'C';
if (x == 'C') return 'A';
}
char right(char x) {
if (x == 'B') return 'A';
if (x == 'C') return 'B';
if (x == 'A') return 'C';
}
namespace J1{
bool judge(ll mid, ll x, ll z) {
if (mid & 1) {
x -= 3 * (mid / 2);
ll y = x;
y = x - 2;
x = x - 1;
if (y >= z + 2) return true;
else return false;
}
else {
x -= 3 * (mid / 2);
if (x >= z + 2) return true;
else return false;
}
}
ll solve(ll l, ll r, ll x, ll z) {
while (l < r) {
ll mid = ((r - l) >> 1) + l;
if (judge(mid, x, z)) l = mid + 1;
else r = mid;
}
return l;
}
}
namespace J2{
bool judge(ll mid, ll x, ll z) {
if (mid & 1) {
x -= 2 * mid;
z -= mid / 2;
ll y = z;
z--;
if (x >= z + 3) return true;
else return false;
}
else {
x -= 2 * mid;
z -= mid / 2;
if (x >= z + 2) return true;
else return false;
}
}
ll solve(ll l, ll r, ll x, ll z) {
while (l < r) {
ll mid = ((r - l) >> 1) + l;
if (judge(mid, x, z)) l = mid + 1;
else r = mid;
}
return l;
}
}
plc ele[10];
int main(){
ll x, y, z;
cin >> x >> y >> z;
ele[1] = plc(x, 'A'), ele[2] = plc(y, 'B'), ele[3] = plc(z, 'C');
sort(ele + 1, ele + 1 + 3);
ll thres = 2ll * (ele[1].fi + ele[2].fi) - 1;
if (ele[3].fi > thres) {
printf("%c %lld\n", ele[3].se, ele[3].fi - thres);
return 0;
}
if (ele[3].fi == thres) {
puts("Rubble!");
return 0;
}
ll stepAB = ele[3].fi - ele[2].fi;
ll stepBC = ele[2].fi - ele[1].fi;
if (stepAB < stepBC) {
ele[3].fi -= 2ll * stepAB;
ele[2].fi -= stepAB;
// A = B > C
ll stepNxt = J1 :: solve(0, 1000000000000000000 + 1, ele[3].fi, ele[1].fi);
ele[3].fi -= 3 * (stepNxt / 2);
ele[2].fi -= 3 * (stepNxt / 2);
if (stepNxt & 1) {
if (left(ele[1].se) == ele[2].se) {
ele[2].fi -= 2;
ele[3].fi -= 1;
}
else {
ele[2].fi -= 1;
ele[3].fi -= 2;
}
}
sort(ele + 1, ele + 1 + 3);
// Normal Mode
assert(ele[3].fi <= ele[1].fi + 2);
}
else {
ele[3].fi -= 2ll * stepBC;
ele[2].fi -= stepBC;
//A > B = C
ll stepNxt = J2 :: solve(0, 1000000000000000000 + 1, ele[3].fi, ele[1].fi);
ele[3].fi -= 2 * stepNxt;
ele[2].fi -= (stepNxt / 2);
ele[1].fi -= (stepNxt / 2);
if (stepNxt & 1) {
if (left(ele[3].se) == ele[1].se) {
ele[1].fi--;
}
else {
ele[2].fi--;
}
}
sort(ele + 1, ele + 1 + 3);
// Normal Mode
assert(ele[3].fi <= ele[1].fi + 2);
}
if (ele[1].fi == ele[2].fi && ele[2].fi < ele[3].fi) {
ll stepFinal = ele[1].fi % 3;
while (stepFinal--) ele[3].se = right(ele[3].se);
printf("%c %lld\n", ele[3].se, 1ll);
}
else puts("Rubble!");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3720kb
input:
10 3 1
output:
A 3
result:
ok single line: 'A 3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
3 2 1
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
2 3 2
output:
C 1
result:
ok single line: 'C 1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3624kb
input:
100 101 100
output:
A 1
result:
ok single line: 'A 1'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3656kb
input:
100 99 100
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3664kb
input:
1000 5000 1000
output:
B 1001
result:
ok single line: 'B 1001'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2000 1000 1000
output:
C 1
result:
ok single line: 'C 1'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
1000000000000000 2000000000000000 4000000000000000
output:
B 1
result:
ok single line: 'B 1'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
1000000000000000 2000000000000000 4000000000000001
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3592kb
input:
1 1 1
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
1000000000000000000 1000000000000000000 1000000000000000000
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3448kb
input:
1000000000000000000 1000000000000000000 999999999999999999
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #13:
score: 0
Accepted
time: 3ms
memory: 3652kb
input:
999999999999999999 999999999999999999 1000000000000000000
output:
C 1
result:
ok single line: 'C 1'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
1000000000000000000 666666666666666666 333333333333333343
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3588kb
input:
1000000000000000000 1000000000000000000 1
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
1000000000000000000 1 1000000000000000000
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #17:
score: 0
Accepted
time: 3ms
memory: 3448kb
input:
1 1000000000000000000 1000000000000000000
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #18:
score: 0
Accepted
time: 3ms
memory: 3728kb
input:
1 1 1000000000000000000
output:
C 999999999999999997
result:
ok single line: 'C 999999999999999997'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3700kb
input:
1 1000000000000000000 1
output:
B 999999999999999997
result:
ok single line: 'B 999999999999999997'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
1000000000000000000 1 1
output:
A 999999999999999997
result:
ok single line: 'A 999999999999999997'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
1 1 2
output:
B 1
result:
ok single line: 'B 1'
Test #22:
score: 0
Accepted
time: 3ms
memory: 3696kb
input:
1 2 1
output:
A 1
result:
ok single line: 'A 1'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3664kb
input:
2 1 1
output:
C 1
result:
ok single line: 'C 1'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
444157599796692942 46675314082485334 560236489768887907
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #25:
score: 0
Accepted
time: 3ms
memory: 3520kb
input:
956755259049838138 412802820832641541 251847321245586964
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
160571653790836855 161115915384424052 109332424445158010
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
921648419000118845 614004066072469867 813008253605106742
output:
C 1
result:
ok single line: 'C 1'
Test #28:
score: 0
Accepted
time: 3ms
memory: 3576kb
input:
693945840953877919 169434960463419660 113866378987295962
output:
A 127343162052446676
result:
ok single line: 'A 127343162052446676'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
85019237241209084 980529565679633437 380691477259981355
output:
B 49108136677252560
result:
ok single line: 'B 49108136677252560'
Test #30:
score: 0
Accepted
time: 2ms
memory: 3568kb
input:
645421234567141464 407893628649180661 364549975476396707
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
738357910767343290 235746790249011133 637016428074206146
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #32:
score: 0
Accepted
time: 3ms
memory: 3656kb
input:
510390692617211911 601079822093185951 71803470531764164
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
107535136359726249 968559233358270701 818866444754832562
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
905098446311590477 720882423525283458 705469307748541766
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #35:
score: 0
Accepted
time: 4ms
memory: 3452kb
input:
954691959809318528 384078665351903019 841953877580378475
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
811244616949995467 72615926345184233 255607189988205136
output:
A 154798384283216730
result:
ok single line: 'A 154798384283216730'
Test #37:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
926193781258448632 164284852574664659 626024798607977342
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #38:
score: 0
Accepted
time: 3ms
memory: 3584kb
input:
105164835967083077 564109255000339084 347544484863227666
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #39:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
335604692427987384 143896955232269694 383635221488408171
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #40:
score: 0
Accepted
time: 3ms
memory: 3452kb
input:
234275783824115394 921676707138510707 630913355295121299
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #41:
score: 0
Accepted
time: 3ms
memory: 3692kb
input:
331646244565684856 105644609571048710 919956442308821358
output:
C 45374734035354227
result:
ok single line: 'C 45374734035354227'
Test #42:
score: 0
Accepted
time: 3ms
memory: 3568kb
input:
365530129751400870 279130545514732915 211986208154388685
output:
Rubble!
result:
ok single line: 'Rubble!'
Test #43:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
947087216394105639 38014606015037878 299824398374458488
output:
A 271409207615112908
result:
ok single line: 'A 271409207615112908'