Submission #445534

# Submission time Handle Problem Language Result Execution time Memory
445534 2021-07-18T14:53:04 Z cpp219 Paths (BOI18_paths) C++14
100 / 100
511 ms 102748 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 3e5 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;

vector<ll> g[N];
ll n,m,k,a[N],x,y,dp[N][33],ans;

bool bit(ll x,ll i){
    return (x >> i) & 1;
}

ll f(ll node,ll mask){
    if (dp[node][mask] != -1) return dp[node][mask];
    ll have = __builtin_popcount(mask);
    ll ans = (have > 1);
    for (auto i : g[node]){
        if (bit(mask,a[i])) continue;
        ans += f(i,mask ^ (1 << a[i]));
    }
    return dp[node][mask] = ans;
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n>>m>>k; memset(dp,-1,sizeof(dp));
    for (ll i = 1;i <= n;i++) cin>>a[i];
    while(m--){
        cin>>x>>y;
        g[x].push_back(y); g[y].push_back(x);
    }
    //cout<<f(1,(1 << a[1])); return 0;
    for (ll i = 1;i <= n;i++) ans += f(i,(1 << a[i]));
    cout<<ans;
}

Compilation message

paths.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
paths.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
paths.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
paths.cpp: In function 'int main()':
paths.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 84808 KB Output is correct
2 Correct 37 ms 84832 KB Output is correct
3 Correct 37 ms 84804 KB Output is correct
4 Correct 39 ms 84796 KB Output is correct
5 Correct 38 ms 84756 KB Output is correct
6 Correct 36 ms 84876 KB Output is correct
7 Correct 37 ms 84776 KB Output is correct
8 Correct 36 ms 84784 KB Output is correct
9 Correct 36 ms 84856 KB Output is correct
10 Correct 38 ms 84752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 94872 KB Output is correct
2 Correct 110 ms 94148 KB Output is correct
3 Correct 425 ms 102200 KB Output is correct
4 Correct 161 ms 96560 KB Output is correct
5 Correct 149 ms 96540 KB Output is correct
6 Correct 320 ms 99336 KB Output is correct
7 Correct 416 ms 102272 KB Output is correct
8 Correct 390 ms 102748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 84808 KB Output is correct
2 Correct 37 ms 84832 KB Output is correct
3 Correct 37 ms 84804 KB Output is correct
4 Correct 39 ms 84796 KB Output is correct
5 Correct 38 ms 84756 KB Output is correct
6 Correct 36 ms 84876 KB Output is correct
7 Correct 37 ms 84776 KB Output is correct
8 Correct 36 ms 84784 KB Output is correct
9 Correct 36 ms 84856 KB Output is correct
10 Correct 38 ms 84752 KB Output is correct
11 Correct 125 ms 94872 KB Output is correct
12 Correct 110 ms 94148 KB Output is correct
13 Correct 425 ms 102200 KB Output is correct
14 Correct 161 ms 96560 KB Output is correct
15 Correct 149 ms 96540 KB Output is correct
16 Correct 320 ms 99336 KB Output is correct
17 Correct 416 ms 102272 KB Output is correct
18 Correct 390 ms 102748 KB Output is correct
19 Correct 128 ms 94916 KB Output is correct
20 Correct 107 ms 94100 KB Output is correct
21 Correct 394 ms 102196 KB Output is correct
22 Correct 200 ms 96628 KB Output is correct
23 Correct 150 ms 96640 KB Output is correct
24 Correct 303 ms 99316 KB Output is correct
25 Correct 406 ms 102308 KB Output is correct
26 Correct 386 ms 102724 KB Output is correct
27 Correct 121 ms 94192 KB Output is correct
28 Correct 157 ms 96348 KB Output is correct
29 Correct 511 ms 102380 KB Output is correct
30 Correct 387 ms 98736 KB Output is correct
31 Correct 411 ms 98800 KB Output is correct
32 Correct 505 ms 102164 KB Output is correct
33 Correct 36 ms 84800 KB Output is correct
34 Correct 37 ms 84764 KB Output is correct
35 Correct 38 ms 84776 KB Output is correct
36 Correct 38 ms 84800 KB Output is correct
37 Correct 38 ms 84748 KB Output is correct
38 Correct 38 ms 84844 KB Output is correct
39 Correct 38 ms 84804 KB Output is correct
40 Correct 37 ms 84872 KB Output is correct
41 Correct 37 ms 84784 KB Output is correct
42 Correct 37 ms 84736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 84844 KB Output is correct
2 Correct 73 ms 87748 KB Output is correct
3 Correct 61 ms 87744 KB Output is correct
4 Correct 120 ms 90452 KB Output is correct
5 Correct 100 ms 90808 KB Output is correct
6 Correct 170 ms 90464 KB Output is correct
7 Correct 66 ms 87668 KB Output is correct
8 Correct 142 ms 90500 KB Output is correct
9 Correct 110 ms 90916 KB Output is correct
10 Correct 132 ms 91108 KB Output is correct
11 Correct 139 ms 88944 KB Output is correct
12 Correct 113 ms 89852 KB Output is correct
13 Correct 132 ms 89316 KB Output is correct
14 Correct 174 ms 90564 KB Output is correct
15 Correct 141 ms 90488 KB Output is correct
16 Correct 38 ms 84804 KB Output is correct
17 Correct 38 ms 84744 KB Output is correct
18 Correct 37 ms 84804 KB Output is correct
19 Correct 38 ms 84800 KB Output is correct
20 Correct 39 ms 84764 KB Output is correct
21 Correct 39 ms 84800 KB Output is correct
22 Correct 37 ms 84856 KB Output is correct
23 Correct 37 ms 84784 KB Output is correct
24 Correct 38 ms 84784 KB Output is correct
25 Correct 37 ms 84788 KB Output is correct