QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74120 | #2571. Aidana and Pita | CSU2023 | WA | 612ms | 94640kb | C++14 | 2.2kb | 2023-01-30 20:31:59 | 2023-01-30 20:32:02 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
const int L = 20;
const int N = 16e5 + 5;
const int N2 = 32e5 + 5;
const ll Minn = -1e18;
const ll Maxn = 1e18;
int p[L], q[L], cs[N2], ex[L];
int n, n1, n2, fm, bm, ans_s1, ans_s2;
ll b[N2], c[N2], ans = Maxn;
struct node
{
int s;
ll a, b;
bool t;
node() {}
node(int S, ll A, ll B, bool T):
s(S), a(A), b(B), t(T) {}
inline bool operator < (const node &x) const
{
return a < x.a || a == x.a && t > x.t;
}
}f[N2];
inline void calc(int s, int *p, int m, ll &x, ll &y, ll &z)
{
x = y = z = 0;
for (int i = 0; i < m; ++i)
{
int g = s / ex[i] % 3;
if (g == 0)
x += p[i + 1];
else if (g == 1)
y += p[i + 1];
else
z += p[i + 1];
}
}
inline void Modify(int x, ll v, int s)
{
for (; x <= bm; x += x & -x)
if (c[x] < v)
{
c[x] = v;
cs[x] = s;
}
}
inline void Query(int x, ll v, int s)
{
for (; x; x ^= x & -x)
if (c[x] != Minn && ans > v - c[x])
{
ans = v - c[x];
ans_s1 = s;
ans_s2 = cs[x];
}
}
int main()
{
scanf("%d", &n);
n1 = n >> 1;
n2 = n - n1;
ex[0] = 1;
for (int i = 1; i <= n1 || i <= n2; ++i)
ex[i] = 3 * ex[i - 1];
for (int i = 1; i <= n1; ++i)
scanf("%d", &p[i]);
for (int i = 1; i <= n2; ++i)
scanf("%d", &q[i]);
for (int s = 0; s < ex[n1]; ++s)
{
ll x, y, z;
calc(s, p, n1, x, y, z);
f[++fm] = node(s, x - y, y - z, 0);
}
for (int s = 0; s < ex[n2]; ++s)
{
ll x, y, z;
calc(s, q, n2, x, y, z);
f[++fm] = node(s, y - x, z - y, 1);
}
for (int i = 1; i <= fm; ++i)
b[++bm] = f[i].b;
std::sort(b + 1, b + bm + 1);
bm = std::unique(b + 1, b + bm + 1) - b - 1;
for (int i = 1; i <= fm; ++i)
f[i].b = std::lower_bound(b + 1, b + bm + 1, f[i].b) - b;
std::sort(f + 1, f + fm + 1);
for (int i = 1; i <= bm; ++i)
c[i] = Minn, cs[i] = -1;
for (int i = 1; i <= fm; ++i)
if (f[i].t)
Modify(f[i].b, f[i].a + f[i].b, f[i].s);
else
Query(f[i].b, f[i].a + f[i].b, f[i].s);
for (int i = 0; i < n1; ++i)
printf("%d ", (ans_s1 / ex[i] % 3) + 1);
for (int i = 0; i < n2; ++i)
printf("%d ", (ans_s2 / ex[i] % 3) + 1);
putchar('\n');
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9688kb
input:
5 2 3 1 4 2
output:
3 2 2 1 3
result:
ok answer is 0
Test #2:
score: 0
Accepted
time: 3ms
memory: 9656kb
input:
6 3 2 5 3 4 2
output:
2 3 1 2 3 1
result:
ok answer is 1
Test #3:
score: 0
Accepted
time: 1ms
memory: 9736kb
input:
3 2617460 3290620 1468912
output:
2 1 3
result:
ok answer is 1821708
Test #4:
score: 0
Accepted
time: 529ms
memory: 94640kb
input:
25 6 6 7 8 5 10 5 7 10 10 4 4 5 8 1 6 3 1 9 4 10 7 8 4 5
output:
2 2 3 2 2 3 2 2 3 2 3 2 1 1 3 3 1 3 1 1 1 1 3 3 1
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 516ms
memory: 93344kb
input:
25 8 2 2 9 9 10 3 5 9 1 2 5 8 1 4 8 4 3 6 2 8 8 4 2 2
output:
2 2 3 2 3 3 2 2 2 2 3 2 1 1 1 1 3 1 1 3 1 3 3 1 1
result:
ok answer is 1
Test #6:
score: -100
Wrong Answer
time: 612ms
memory: 94108kb
input:
25 9999996 9999999 9999991 9999991 9999999 9999997 9999991 9999993 9999992 10000000 9999991 10000000 9999996 9999997 9999993 9999992 9999990 9999991 9999997 10000000 9999998 9999990 9999993 9999990 9999999
output:
3 3 1 1 3 3 1 3 1 3 1 3 1 2 2 2 2 1 2 1 1 2 2 2 2
result:
wrong answer expected 9999943, found 19999957