10014 | 2024-03-24 09:49:04 | 111 | Autópálya infláció | cpp17 | Time limit exceeded 0/100 | 2.099s | 13284 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
bitset<3072> add(bitset<3072> a, bitset<3072> b) {
bitset<3072> result;
int carry = 0;
for (int i = 0; i < 3072; i++) {
int sum = a[i] + b[i] + carry;
result[i] = sum & 1;
carry = sum >> 1;
}
return result;
}
struct B{
bitset<3072>b;
B(bitset<3072>b):b(b){
}
B(int x,int p):b(bitset<3072>(x)<<p){
}
operator int(){
int r=0;
int p=1;
for(int i=0;i<3072;i++){
r+=b[i]*p;
r%=MOD;
p*=2;
p%=MOD;
}
return r;
}
friend B operator+(B a,B b){
return B(add(a.b,b.b));
}
friend B operator<<(B a,int h){
return B(a.b<<h);
}
friend bool operator<(B a,B b){
for(int i=3071;i>=0;i--){
if(!a.b[i]&&b.b[i]){
return true;
}
if(a.b[i]&&!b.b[i]){
return false;
}
}
return false;
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<vector<pair<int,B>>>g(N);
for(int i=0;i<M;i++){
int a,b,w;
cin>>a>>b>>w;
a--,b--;
g[a].emplace_back(b,B(w,0));
g[b].emplace_back(a,B(w,0));
}
vector<array<B,2>>dp(N,{B(1,N*2),B(1,N*2)});
dp[0][0]=B(0,0);
for(int i=0;i+1<N;i++){
vector<int>v;
for(int j=0;j<N;j++){
if(i>0&&dp[j][i&1]>=dp[j][i&1^1]){
dp[j][i&1]=dp[j][i&1^1];
continue;
}
v.push_back(j);
}
for(int j:v){
for(auto[k,w]:g[j]){
auto c=dp[j][i&1]+(w<<i);
if(c<dp[k][i&1^1]){
dp[k][i&1^1]=c;
}
}
}
}
for(int i=1;i<N;i++){
cout<<(int)dp[i][(N-1)&1]<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 4ms | 1708 KiB | ||||
2 | Time limit exceeded | 2.099s | 10096 KiB | ||||
subtask2 | 0/8 | ||||||
3 | Time limit exceeded | 2.082s | 6896 KiB | ||||
4 | Time limit exceeded | 2.069s | 6572 KiB | ||||
5 | Time limit exceeded | 2.062s | 6876 KiB | ||||
6 | Time limit exceeded | 2.099s | 7104 KiB | ||||
7 | Time limit exceeded | 2.062s | 6844 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Wrong answer | 6ms | 3100 KiB | ||||
9 | Accepted | 7ms | 3044 KiB | ||||
10 | Wrong answer | 6ms | 3172 KiB | ||||
11 | Wrong answer | 6ms | 3240 KiB | ||||
12 | Wrong answer | 6ms | 3328 KiB | ||||
13 | Wrong answer | 7ms | 3656 KiB | ||||
14 | Wrong answer | 6ms | 3460 KiB | ||||
15 | Wrong answer | 6ms | 3652 KiB | ||||
16 | Wrong answer | 7ms | 3660 KiB | ||||
17 | Accepted | 4ms | 3868 KiB | ||||
18 | Wrong answer | 4ms | 3948 KiB | ||||
subtask4 | 0/34 | ||||||
19 | Time limit exceeded | 2.065s | 12036 KiB | ||||
20 | Time limit exceeded | 2.069s | 12076 KiB | ||||
21 | Time limit exceeded | 2.046s | 12036 KiB | ||||
22 | Time limit exceeded | 2.062s | 11972 KiB | ||||
23 | Time limit exceeded | 2.069s | 12036 KiB | ||||
24 | Time limit exceeded | 2.062s | 11960 KiB | ||||
25 | Time limit exceeded | 2.042s | 11868 KiB | ||||
26 | Time limit exceeded | 2.062s | 11332 KiB | ||||
27 | Time limit exceeded | 2.062s | 10312 KiB | ||||
28 | Time limit exceeded | 2.055s | 8320 KiB | ||||
29 | Time limit exceeded | 2.069s | 8440 KiB | ||||
30 | Time limit exceeded | 2.071s | 8344 KiB | ||||
31 | Time limit exceeded | 2.082s | 8432 KiB | ||||
32 | Time limit exceeded | 2.082s | 12000 KiB | ||||
33 | Time limit exceeded | 2.069s | 12016 KiB | ||||
subtask5 | 0/21 | ||||||
34 | Time limit exceeded | 2.062s | 5228 KiB | ||||
35 | Time limit exceeded | 2.066s | 6464 KiB | ||||
36 | Time limit exceeded | 2.082s | 6592 KiB | ||||
37 | Time limit exceeded | 2.055s | 6796 KiB | ||||
38 | Time limit exceeded | 2.038s | 6540 KiB | ||||
39 | Time limit exceeded | 2.066s | 6904 KiB | ||||
40 | Time limit exceeded | 2.078s | 6388 KiB | ||||
41 | Time limit exceeded | 2.078s | 6060 KiB | ||||
42 | Time limit exceeded | 2.082s | 4948 KiB | ||||
43 | Time limit exceeded | 2.042s | 4936 KiB | ||||
44 | Time limit exceeded | 2.072s | 4960 KiB | ||||
45 | Time limit exceeded | 2.049s | 4868 KiB | ||||
46 | Time limit exceeded | 2.065s | 4992 KiB | ||||
47 | Time limit exceeded | 2.059s | 4964 KiB | ||||
48 | Time limit exceeded | 2.069s | 5444 KiB | ||||
49 | Time limit exceeded | 2.069s | 5596 KiB | ||||
subtask6 | 0/22 | ||||||
50 | Time limit exceeded | 2.062s | 13040 KiB | ||||
51 | Time limit exceeded | 2.069s | 13052 KiB | ||||
52 | Time limit exceeded | 2.046s | 12928 KiB | ||||
53 | Time limit exceeded | 2.046s | 13284 KiB | ||||
54 | Time limit exceeded | 2.078s | 12600 KiB | ||||
55 | Time limit exceeded | 2.082s | 12388 KiB | ||||
56 | Time limit exceeded | 2.065s | 11156 KiB | ||||
57 | Time limit exceeded | 2.073s | 11268 KiB | ||||
58 | Time limit exceeded | 2.069s | 5772 KiB | ||||
59 | Time limit exceeded | 2.049s | 9040 KiB | ||||
60 | Time limit exceeded | 2.065s | 9076 KiB | ||||
61 | Time limit exceeded | 2.058s | 9148 KiB | ||||
62 | Time limit exceeded | 2.069s | 9028 KiB | ||||
63 | Time limit exceeded | 2.03s | 9060 KiB | ||||
64 | Time limit exceeded | 2.099s | 12384 KiB | ||||
65 | Time limit exceeded | 2.075s | 12320 KiB | ||||
66 | Time limit exceeded | 2.062s | 11476 KiB |