# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
379719 |
2021-03-19T05:05:23 Z |
wzy |
Džumbus (COCI19_dzumbus) |
C++11 |
|
309 ms |
59372 KB |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 1005;
const ll inf = (ll) 1e15;
int n , m , d[N] , vis[N] , sz[N];
vector<int> g[N];
vector< vl > dp[N];
ll cost[N];
void comb(vector<vl> &a , vector<vl> &b){
vector<vl> c(sz(a) + sz(b) + 2, vl(3,inf));
auto add = [&](int a , int b){
if(a == 1){
if(b == 1)
return 2;
else
return (b > 0 ? 1 : 0);
}
if(a == 2){
return (b == 1 ? 1 : 0);
}
return 0;
};
auto state = [&](int a , int b){
if(a == 1){
if(b > 0)
return 2;
}
if(a == 2){
if(b > 0)
return 2;
}
return a;
};
for(int i = 0 ; i < sz(a) ; i ++){
for(int j = 0 ; j < sz(b); j ++){
for(int k = 0 ; k < 3; k ++){
for(int w = 0 ; w < 3 ; w++){
c[i+j+add(k,w)][state(k,w)] = min(c[i+j+add(k,w)][state(k,w)],a[i][k] + b[j][w]);
}
}
}
}
swap(c,a);
}
void dfs(int x){
sz[x] = 1;
dp[x] = vector<vl>(1,vl(3,0));
dp[x][0][1] = d[x];
dp[x][0][2] = inf;
for(auto w : g[x]){
if(!vis[w]){
vis[w] = vis[x];
dfs(w);
comb(dp[x] , dp[w]);
sz[x] += sz[w];
}
}
}
int32_t main(){
scanf("%d%d" , &n , &m);
for(int i = 1 ; i <= n; i ++)
scanf("%d" , &d[i]);
for(int i = 1; i <= m; i ++){
int u , v;
scanf("%d%d" , &u , &v);
g[u].push_back(v);
g[v].push_back(u);
}
fill(cost,cost+N,inf);
cost[0] = 0;
for(int i = 1 ; i <= n; i ++){
if(!vis[i]){
vis[i] = i;
dfs(i);
for(int j = n; j >= 1; j --){
for(int k = 0 ; k <= min(sz(dp[i]),j) ; k ++){
cost[j] = min(cost[j] , cost[j-k] + min({dp[i][k][0] , dp[i][k][1] , dp[i][k][2]}));
}
}
for(int j = 1; j <= n; j ++)
cost[j] = min(cost[j] , cost[j+1]);
}
}
vl p;
for(int i = 0 ; i <= n; i ++){
if(cost[i] >= inf)
break;
p.push_back(cost[i]);
}
int q;
scanf("%d" , &q);
for(int _ = 0 ; _ < q; _ ++){
ll s;
scanf("%lld" , & s);
auto ans = upper_bound(all(p) , s) - begin(p) - 1;
printf("%d\n" , (int)ans);
}
}
Compilation message
dzumbus.cpp: In function 'int32_t main()':
dzumbus.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
80 | scanf("%d%d" , &n , &m);
| ~~~~~^~~~~~~~~~~~~~~~~~
dzumbus.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
82 | scanf("%d" , &d[i]);
| ~~~~~^~~~~~~~~~~~~~
dzumbus.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
85 | scanf("%d%d" , &u , &v);
| ~~~~~^~~~~~~~~~~~~~~~~~
dzumbus.cpp:111:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
111 | scanf("%d" , &q);
| ~~~~~^~~~~~~~~~~
dzumbus.cpp:114:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
114 | scanf("%lld" , & s);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
45548 KB |
Output is correct |
2 |
Correct |
243 ms |
53356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
45548 KB |
Output is correct |
2 |
Correct |
243 ms |
53356 KB |
Output is correct |
3 |
Correct |
292 ms |
59372 KB |
Output is correct |
4 |
Correct |
309 ms |
44908 KB |
Output is correct |
5 |
Correct |
307 ms |
42348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
1516 KB |
Output is correct |
2 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
248 ms |
45548 KB |
Output is correct |
2 |
Correct |
243 ms |
53356 KB |
Output is correct |
3 |
Correct |
292 ms |
59372 KB |
Output is correct |
4 |
Correct |
309 ms |
44908 KB |
Output is correct |
5 |
Correct |
307 ms |
42348 KB |
Output is correct |
6 |
Correct |
52 ms |
1516 KB |
Output is correct |
7 |
Runtime error |
1 ms |
620 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |