QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#399665 | #2823. 改善生活 | ucup-team1251 | WA | 6ms | 6472kb | C++20 | 1.7kb | 2024-04-26 16:39:59 | 2024-04-26 16:40:00 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#define Buff ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 705;
struct LB
{
int to, nx;
}b[700 * 710];
int hd[710], idx;
void ini()
{
idx = 1;
for(int i = 0; i < 710; i++)
hd[i] = -1;
}
void add(int x, int y)
{
b[idx].to = y;
b[idx].nx = hd[x];
hd[x] = idx++;
}
int dx;
vector<int> vis[710];
bool vvis[710];
void dfs(int u)
{
if(vvis[u])
return;
vvis[u] = 1;
vis[u].emplace_back(dx);
for(int i = hd[u]; i != -1; i = b[i].nx)
{
dfs(b[i].to);
}
}
int c[N], w[N];
int sum[710][710];
void solve()
{
ini();
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> c[i];
for(int i = 1; i <= n; i++) cin >> w[i];
for(int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
add(u, v);
}
for(int i = 1; i <= n; i++)
{
if(c[i] == 1)
{
dx = i;
memset(vvis, 0, sizeof(vvis));
dfs(i);
}
}
vector<int> c1, c2;
for(int i = 1; i <= n; i++)
{
if(c[i] != 1)
{
c2.emplace_back(i);
if(vis[i].empty())
continue;
for(auto& j : vis[i])
{
sum[j][c[i]] += w[i];
}
}
else
c1.emplace_back(i);
}
double mx = -1;
for(auto& i : c2)
{
ll a1 = 0, a2 = 0;
for(auto& j : c1)
{
if(sum[j][c[i]] >= w[j])
{
ll fz = sum[j][c[i]];
ll fm = w[j];
if(a2 == 0 || fz * 1.0 / fm > a1 * 1.0 / a2)
{
a1 = fz;
a2 = fm;
}
}
}
if(a2 > 0)
mx = max(mx, a1 * 1.0 / a2);
}
cout << (ll)mx << '\n';
}
int main()
{
Buff;
int N = 1;
//cin >> N;
while(N--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5840kb
input:
7 8 2 2 1 1 3 3 4 100 100 40 20 100 50 40 1 3 2 3 1 4 2 4 3 5 4 6 3 7 4 7
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
15 36 1 1 1 1 1 1 1 3 3 4 5 5 6 4 2 1 5 4 16 1 16 9 98 84 69 4 95 53 99 64 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 8 11 9 8 9 10 9 11 9 12 9 14 10 8 10 11 10 12 11 8 11 9 11 10 11 12 11 14 12 13 12 14 13 8 13 9 13 10 13 12 13 14 13 15 14 10 14 13 14 15 15 9 15 11 15 13
output:
182
result:
ok single line: '182'
Test #3:
score: 0
Accepted
time: 0ms
memory: 6080kb
input:
700 200 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 688 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 126 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
77
result:
ok single line: '77'
Test #4:
score: 0
Accepted
time: 2ms
memory: 6472kb
input:
700 2000 1 1 1 1 1 1 1 1 1 1 1 122 1 1 1 1 1 1 1 1 1 1 62 1 1 1 1 1 1 1 1 1 1 1 1 367 1 1 317 1 1 318 1 1 1 215 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 152 105 1 1 1 1 1 1 1 1 1 1 1 1 694 342 164 158 1 529 1 1 1 1 1 71 517 1 1 221 1 619 1 1 1 1 171 597 665 1 210 101 1 91 1 1 69 1 1 1 230 590 1 412 1 1 1 1 1 4...
output:
77
result:
ok single line: '77'
Test #5:
score: 0
Accepted
time: 6ms
memory: 5808kb
input:
700 60000 1 1 41 1 364 447 498 1 1 1 407 543 471 516 97 423 531 147 88 1 266 1 468 114 65 357 202 1 257 250 295 309 228 640 201 401 534 50 416 650 116 470 333 344 688 178 225 683 295 490 426 439 688 180 293 219 241 209 139 460 659 699 659 408 172 146 649 399 123 567 145 90 490 626 630 270 161 541 13...
output:
77
result:
ok single line: '77'
Test #6:
score: 0
Accepted
time: 3ms
memory: 5952kb
input:
700 60000 1 1 299 1 1 170 38 275 272 595 1 267 416 414 29 1 651 146 393 585 413 669 659 235 166 453 396 637 87 228 153 366 608 467 321 434 296 317 65 162 484 359 366 487 580 657 650 126 680 531 413 281 65 339 542 44 154 372 121 144 610 143 341 612 186 183 407 628 146 628 333 420 504 521 429 234 677 ...
output:
13
result:
ok single line: '13'
Test #7:
score: 0
Accepted
time: 3ms
memory: 5768kb
input:
700 60000 1 1 1 1 240 1 68 228 1 167 573 449 1 529 1 240 529 176 207 222 529 462 609 323 19 581 132 252 408 448 470 424 562 53 442 40 26 311 623 123 185 247 400 630 231 622 343 268 639 572 368 396 173 531 60 296 309 317 102 68 561 77 232 148 657 677 406 648 626 448 63 50 29 417 19 231 525 500 20 78 ...
output:
84
result:
ok single line: '84'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5976kb
input:
200 350 1 1 1 1 22 1 1 1 1 1 21 1 1 1 84 1 1 1 1 49 1 1 40 48 1 17 1 39 1 39 1 1 53 127 1 47 59 9 1 23 1 73 1 5 15 18 20 14 1 45 3 65 1 9 56 2 57 1 105 1 1 1 22 1 43 6 3 34 8 56 78 1 12 47 18 75 2 50 17 12 27 37 1 13 54 15 2 11 36 13 24 52 138 10 35 17 44 15 38 22 54 29 3 55 16 24 31 11 42 86 13 12 ...
output:
116
result:
ok single line: '116'
Test #9:
score: 0
Accepted
time: 1ms
memory: 5980kb
input:
300 541 1 1 1 1 1 1 1 1 1 1 200 1 1 1 1 30 1 1 1 1 1 1 1 1 1 44 1 1 1 83 1 1 1 1 1 1 1 1 34 71 1 1 1 1 1 1 109 1 1 78 11 1 1 1 1 35 24 1 1 24 49 1 29 13 1 1 5 30 64 1 121 140 1 1 20 1 100 21 4 39 1 27 54 1 1 1 1 116 98 1 1 1 1 1 1 1 1 19 190 3 3 227 44 36 34 84 10 3 1 1 31 45 1 50 11 1 1 178 52 1 67...
output:
190
result:
ok single line: '190'
Test #10:
score: 0
Accepted
time: 1ms
memory: 6032kb
input:
400 1140 1 1 1 1 1 1 240 1 1 1 101 1 1 1 1 1 2 29 1 155 1 1 51 1 1 1 1 1 1 1 1 128 1 89 1 18 42 1 1 1 28 15 88 1 1 73 1 1 1 56 1 1 50 1 1 1 84 148 1 1 141 11 1 20 1 1 1 1 1 1 46 112 135 1 105 27 134 3 163 35 74 1 16 1 14 135 1 1 98 1 6 204 305 136 211 134 106 29 11 44 10 46 1 1 96 220 149 1 1 105 91...
output:
229
result:
ok single line: '229'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5968kb
input:
500 1214 1 1 1 1 1 1 1 1 1 1 1 36 1 1 1 1 1 1 56 91 1 56 1 1 1 118 1 1 29 1 127 1 1 1 1 1 1 1 11 178 1 1 1 1 276 23 1 46 66 1 63 310 1 278 70 1 1 1 18 1 1 1 54 7 1 1 177 87 196 1 41 1 19 1 92 68 35 38 39 224 14 1 2 139 1 1 1 1 62 240 17 1 11 278 92 96 269 135 1 63 106 311 20 106 1 1 116 110 16 195 2...
output:
191
result:
ok single line: '191'
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
2 1 2 1 1 1 1 2
output:
-1
result:
wrong answer 1st lines differ - expected: '0', found: '-1'