답안 #648152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648152 2022-10-05T14:25:14 Z jcelin Paths (BOI18_paths) C++14
100 / 100
426 ms 57728 KB
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vll>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 3e5 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 5;
const int off = 1 << logo;
const int trsz = off << 1;

ll n, m, k;
ll arr[MAXN], dp[off][MAXN], ans;

vi g[MAXN];

void solve(){
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) cin >> arr[i], arr[i]--;
	for(int i = 1, a, b; i <= m; i++) cin >> a >> b, g[a].PB(b), g[b].PB(a);
	
	for(ll x = 1; x < (1 << k); x++) for(ll i = 1; i <= n; i++){
		if(x & (1 << arr[i]) == 0) continue;
		ll j = (1 << arr[i]);
		if(j == x) dp[x][i] = 1;
		for(auto &y : g[i]) dp[x][i] += dp[x ^ j][y];
		ans += dp[x][i];
	}
	cout << ans - n << "\n";
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}






Compilation message

paths.cpp: In function 'void solve()':
paths.cpp:65:24: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   65 |   if(x & (1 << arr[i]) == 0) continue;
      |          ~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7508 KB Output is correct
2 Correct 6 ms 7500 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 4 ms 7508 KB Output is correct
8 Correct 4 ms 7424 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 14156 KB Output is correct
2 Correct 60 ms 13248 KB Output is correct
3 Correct 266 ms 39116 KB Output is correct
4 Correct 98 ms 16040 KB Output is correct
5 Correct 81 ms 15588 KB Output is correct
6 Correct 232 ms 31004 KB Output is correct
7 Correct 251 ms 38992 KB Output is correct
8 Correct 264 ms 39632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7508 KB Output is correct
2 Correct 6 ms 7500 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 4 ms 7508 KB Output is correct
8 Correct 4 ms 7424 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 73 ms 14156 KB Output is correct
12 Correct 60 ms 13248 KB Output is correct
13 Correct 266 ms 39116 KB Output is correct
14 Correct 98 ms 16040 KB Output is correct
15 Correct 81 ms 15588 KB Output is correct
16 Correct 232 ms 31004 KB Output is correct
17 Correct 251 ms 38992 KB Output is correct
18 Correct 264 ms 39632 KB Output is correct
19 Correct 82 ms 14164 KB Output is correct
20 Correct 51 ms 13280 KB Output is correct
21 Correct 259 ms 39056 KB Output is correct
22 Correct 121 ms 16088 KB Output is correct
23 Correct 118 ms 15556 KB Output is correct
24 Correct 162 ms 31072 KB Output is correct
25 Correct 263 ms 39028 KB Output is correct
26 Correct 337 ms 39604 KB Output is correct
27 Correct 61 ms 13400 KB Output is correct
28 Correct 79 ms 15856 KB Output is correct
29 Correct 426 ms 57728 KB Output is correct
30 Correct 209 ms 35988 KB Output is correct
31 Correct 234 ms 36052 KB Output is correct
32 Correct 419 ms 57684 KB Output is correct
33 Correct 5 ms 7508 KB Output is correct
34 Correct 5 ms 7460 KB Output is correct
35 Correct 6 ms 7380 KB Output is correct
36 Correct 4 ms 7372 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 4 ms 7504 KB Output is correct
39 Correct 5 ms 7512 KB Output is correct
40 Correct 5 ms 7508 KB Output is correct
41 Correct 4 ms 7504 KB Output is correct
42 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 24 ms 9556 KB Output is correct
3 Correct 19 ms 9208 KB Output is correct
4 Correct 72 ms 17748 KB Output is correct
5 Correct 50 ms 18496 KB Output is correct
6 Correct 141 ms 36812 KB Output is correct
7 Correct 32 ms 9292 KB Output is correct
8 Correct 93 ms 24052 KB Output is correct
9 Correct 81 ms 24828 KB Output is correct
10 Correct 121 ms 24684 KB Output is correct
11 Correct 77 ms 23004 KB Output is correct
12 Correct 89 ms 30404 KB Output is correct
13 Correct 72 ms 23192 KB Output is correct
14 Correct 121 ms 36748 KB Output is correct
15 Correct 173 ms 36796 KB Output is correct
16 Correct 5 ms 7508 KB Output is correct
17 Correct 4 ms 7508 KB Output is correct
18 Correct 5 ms 7456 KB Output is correct
19 Correct 5 ms 7380 KB Output is correct
20 Correct 4 ms 7340 KB Output is correct
21 Correct 7 ms 7508 KB Output is correct
22 Correct 4 ms 7508 KB Output is correct
23 Correct 5 ms 7500 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct