답안 #100242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100242 2019-03-10T03:54:59 Z shafinalam Paths (BOI18_paths) C++14
100 / 100
824 ms 169020 KB
#include <bits/stdc++.h>

using namespace std;

const int mx = 3e5+5;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

#define  sf scanf
#define  pf printf

#define  input freopen("input.txt","r",stdin)
#define  output freopen("output.txt","w",stdout)

#define  inf 1e16
#define  ff first
#define  ss second
#define  MP make_pair
#define  pb push_back
#define  all(v) v.begin(), v.end()
#define  printcase(cases) printf("Case %d:", cases);
#define  Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define  FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define  endl printf("\n")
#define  __lcm(a, b) ((a*b)/__gcd(a, b))

int  Set(int N,int pos){return N=N | (1<<pos);}
int  reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}

vector<int>adj[mx];
ll dp[mx][1<<6];
int arr[mx];

ll solve(int u, int mask)
{
    if(dp[u][mask]!=-1) return dp[u][mask];
    ll ans = 0;
    for(int i = 0; i < adj[u].size(); i++)
    {
        int v = adj[u][i];
        if(check(mask, arr[v])) continue;
        ans+=solve(v, Set(mask, arr[v]))+1;
    }
    return dp[u][mask] = ans;
}
int main()
{
    int n, m, k;
    sf("%d%d%d", &n, &m, &k);

    for(int i = 1; i <= n; i++) sf("%d", &arr[i]);
    while(m--)
    {
        int u, v;
        sf("%d%d", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    memset(dp, -1, sizeof dp);
    ll ans = 0, mask = 0;
    for(int i = 1; i <= n; i++) ans+=solve(i, Set(mask, arr[i]));
    pf("%lld\n", ans);
    return 0;
}

Compilation message

paths.cpp: In function 'll solve(int, int)':
paths.cpp:42:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++)
                    ~~^~~~~~~~~~~~~~~
paths.cpp: In function 'int main()':
paths.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     sf("%d%d%d", &n, &m, &k);
       ^
paths.cpp:55:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) sf("%d", &arr[i]);
                                   ^
paths.cpp:59:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         sf("%d%d", &u, &v);
           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 157688 KB Output is correct
2 Correct 137 ms 157688 KB Output is correct
3 Correct 137 ms 157696 KB Output is correct
4 Correct 121 ms 157688 KB Output is correct
5 Correct 123 ms 157688 KB Output is correct
6 Correct 123 ms 157644 KB Output is correct
7 Correct 123 ms 157644 KB Output is correct
8 Correct 138 ms 157660 KB Output is correct
9 Correct 137 ms 157712 KB Output is correct
10 Correct 130 ms 157692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 162228 KB Output is correct
2 Correct 200 ms 162052 KB Output is correct
3 Correct 700 ms 168352 KB Output is correct
4 Correct 398 ms 163068 KB Output is correct
5 Correct 368 ms 163212 KB Output is correct
6 Correct 482 ms 166508 KB Output is correct
7 Correct 700 ms 168764 KB Output is correct
8 Correct 666 ms 169012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 157688 KB Output is correct
2 Correct 137 ms 157688 KB Output is correct
3 Correct 137 ms 157696 KB Output is correct
4 Correct 121 ms 157688 KB Output is correct
5 Correct 123 ms 157688 KB Output is correct
6 Correct 123 ms 157644 KB Output is correct
7 Correct 123 ms 157644 KB Output is correct
8 Correct 138 ms 157660 KB Output is correct
9 Correct 137 ms 157712 KB Output is correct
10 Correct 130 ms 157692 KB Output is correct
11 Correct 231 ms 162228 KB Output is correct
12 Correct 200 ms 162052 KB Output is correct
13 Correct 700 ms 168352 KB Output is correct
14 Correct 398 ms 163068 KB Output is correct
15 Correct 368 ms 163212 KB Output is correct
16 Correct 482 ms 166508 KB Output is correct
17 Correct 700 ms 168764 KB Output is correct
18 Correct 666 ms 169012 KB Output is correct
19 Correct 273 ms 162428 KB Output is correct
20 Correct 221 ms 162212 KB Output is correct
21 Correct 706 ms 168312 KB Output is correct
22 Correct 337 ms 163348 KB Output is correct
23 Correct 303 ms 163392 KB Output is correct
24 Correct 451 ms 166760 KB Output is correct
25 Correct 562 ms 168484 KB Output is correct
26 Correct 620 ms 169020 KB Output is correct
27 Correct 261 ms 162296 KB Output is correct
28 Correct 306 ms 163192 KB Output is correct
29 Correct 716 ms 168316 KB Output is correct
30 Correct 658 ms 165400 KB Output is correct
31 Correct 680 ms 165520 KB Output is correct
32 Correct 824 ms 168444 KB Output is correct
33 Correct 128 ms 157688 KB Output is correct
34 Correct 132 ms 157724 KB Output is correct
35 Correct 134 ms 157660 KB Output is correct
36 Correct 118 ms 157688 KB Output is correct
37 Correct 124 ms 157636 KB Output is correct
38 Correct 129 ms 157688 KB Output is correct
39 Correct 131 ms 157616 KB Output is correct
40 Correct 130 ms 157684 KB Output is correct
41 Correct 128 ms 157624 KB Output is correct
42 Correct 128 ms 157752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 157724 KB Output is correct
2 Correct 173 ms 159440 KB Output is correct
3 Correct 158 ms 159432 KB Output is correct
4 Correct 262 ms 162168 KB Output is correct
5 Correct 242 ms 162672 KB Output is correct
6 Correct 359 ms 162008 KB Output is correct
7 Correct 177 ms 159480 KB Output is correct
8 Correct 296 ms 162080 KB Output is correct
9 Correct 216 ms 162800 KB Output is correct
10 Correct 282 ms 162544 KB Output is correct
11 Correct 291 ms 161036 KB Output is correct
12 Correct 247 ms 161860 KB Output is correct
13 Correct 290 ms 161136 KB Output is correct
14 Correct 324 ms 162124 KB Output is correct
15 Correct 345 ms 162248 KB Output is correct
16 Correct 119 ms 157688 KB Output is correct
17 Correct 135 ms 157816 KB Output is correct
18 Correct 148 ms 157600 KB Output is correct
19 Correct 131 ms 157736 KB Output is correct
20 Correct 139 ms 157660 KB Output is correct
21 Correct 137 ms 157600 KB Output is correct
22 Correct 124 ms 157688 KB Output is correct
23 Correct 137 ms 157704 KB Output is correct
24 Correct 150 ms 157640 KB Output is correct
25 Correct 132 ms 157688 KB Output is correct