QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#322408 | #6769. Monster Hunter | Yarema# | TL | 1ms | 3600kb | C++14 | 3.0kb | 2024-02-06 23:50:15 | 2024-02-06 23:50:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int MAGIC = 10;
void print(vector<LL> a, string s)
{
cout << s << '\n';
for (auto k : a)
cerr << k << ' ';
cerr << '\n';
}
bool can(VI& h, vector<LL> cnt)
{
//print(cnt, "CNT");
int m = SZ(h);
vector<LL> a(m);
FOR (i, 0, m)
{
if (h[i] <= MAGIC)
a[i] = h[i];
else
{
LL c = (h[i] - MAGIC) / 3;
a[i] = h[i] - c * 3;
LL x = min(c, cnt[2]);
cnt[2] -= x;
c -= x;
cnt[0] -= c;
cnt[1] -= c;
}
}
if (*min_element(ALL(cnt)) < 0)
return false;
FOR (i, 0, m)
{
if (cnt[2] == 0)
break;
if (a[i] < 3)
continue;
if (a[i] & 1)
{
a[i] -= 3;
cnt[2]--;
}
}
FOR (i, 0, m)
{
if (a[i] & 1 && cnt[0])
{
a[i]--;
cnt[0]--;
}
}
//print(cnt, "CNT");
//print(a, "A");
if (cnt[0] == 0 && cnt[2] == 0)
{
LL y = 0;
FOR (i, 0, m)
{
y += (a[i] + 1) / 2;
}
return cnt[1] >= y;
}
vector<LL> c(MAGIC + 1);
FOR (i, 0, m)
c[a[i]]++;
int j = 0;
//print(c, "C");
while (c[1] > 0 && j < 3)
{
LL x = min((LL)c[1], cnt[j]);
cnt[j] -= x;
c[1] -= x;
j++;
}
j = 1;
if (c[2] > 0 && j < 3)
{
LL x = min((LL)c[2], cnt[j]);
cnt[j] -= x;
c[2] -= x;
j++;
}
if (max(c[1], c[2]) > 0)
return false;
LL four = min(cnt[0], cnt[2]);
cnt[0] -= four;
cnt[2] -= four;
cnt[1] += cnt[2];
cnt[1] += cnt[0] / 2;
LL x = min(four, c[4]);
c[4] -= x;
four -= x;
x = min(four, c[6]);
c[6] -= x;
four -= x;
c[2] += x;
cnt[1] += four;
x = min(c[4], cnt[1] / 2);
c[4] -= x;
cnt[1] -= x * 2;
x = min(c[6], cnt[1] / 3);
c[6] -= x;
cnt[1] -= x * 3;
x = min(c[2], cnt[1]);
c[2] -= x;
cnt[1] -= x;
//print(c, "c");
c[0] = 0;
return *max_element(ALL(c)) == 0;
}
void solve()
{
int n;
cin >> n;
VI a(n);
VI c(3, 0);
vector<VI> cnt(3, VI(n + 1));
FOR (i, 0, n)
{
cin >> a[i];
a[i]--;
c[a[i]]++;
cnt[a[i]][i + 1]++;
}
FOR (i, 0, 3)
FOR (j, 1, n + 1)
cnt[i][j] += cnt[i][j - 1];
int m;
cin >> m;
VI v(m);
FOR (i, 0, m)
cin >> v[i];
LL sum = accumulate(ALL(v), 0ll);
LL l = 0, r = 1e15;
while (l + 1 < r)
{
LL mid = (l + r) / 2;
vector<LL> cn(3);
LL all = mid / n;
FOR (i, 0, 3)
cn[i] = c[i] * all + cnt[i][mid % n];
LL s2 = cn[0] + cn[1] * 2 + cn[2] * 3;
if (s2 < sum)
{
l = m;
continue;
}
//cerr << mid << ":\n";
if (can(v, cn))
r = mid;
else
l = mid;
}
cout << r << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
input:
2 2 3 2 3 2 4 2 5 1 2 3 2 1 2 3 3
output:
4 3
result:
ok 2 lines
Test #2:
score: -100
Time Limit Exceeded
input:
100 21 1 3 3 3 2 3 3 2 2 1 3 2 1 3 2 1 1 1 3 3 3 3 3 3 1 19 1 3 1 1 3 3 1 3 2 3 2 2 3 3 1 1 2 2 2 10 2 2 3 1 5 2 2 5 5 3 8 1 3 3 1 3 2 3 1 3 1 2 1 27 1 1 1 2 1 3 1 2 2 3 3 3 1 1 1 1 2 1 2 2 2 2 3 2 1 3 2 4 5 1 2 2 23 2 1 3 2 3 2 2 3 1 2 1 3 1 2 3 1 3 1 2 2 2 1 1 10 4 3 5 4 5 4 1 4 3 4 8 1 2 1 3 2 3 ...