답안 #153164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153164 2019-09-12T16:09:52 Z Swan Paths (BOI18_paths) C++14
100 / 100
489 ms 97804 KB
#include <bits/stdc++.h>
#define stop system("pause")
#define INP freopen("input.txt","r",stdin)
#define OUTP freopen("solve1.txt","w",stdout)
#define int long long
using namespace std;

typedef long long ll;

vector<vector<int> > v;
const int maxn = 4e5;
int color[maxn];
int cnt[maxn][(1<<5)];
int n,m,k;

struct st{
    int mask;
    int sz;
    bool operator<(st b)const{
        return sz < b.sz;
    }
    st(int a,int b){
        mask = a;
        sz = b;
    }
};

int get_cnt(int x){
    int res = 0;
    while(x){
        res+=x%2;
        x/=2;
    }
    return res;
}

bool check(int mask,int x){
    return (mask&(1<<x));
}

void print_mask(int mask){
    for(int i(0) ; i < 5;i++){
        if(mask&(1<<i))cout << i+1 << ' ';
    }
    cout << endl;
}

void solve(int mask){
    for(int i(0); i < n;i++){
        if(!check(mask,color[i]))continue;
        int wout = mask^(1<<color[i]);
        //if(i == 0 && mask == 3)print_mask(wout);
        for(int j(0);j < v[i].size();j++){
            int to = v[i][j];
            //if(i == 0 && mask == 3)cout <<mask << ' ' << wout << ' ' << cnt[to][wout] << endl;
            cnt[i][mask]+=cnt[to][wout];
        }
    }
}

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> k;
    v.resize(n+2);
    for(int i(0); i < n;i++){
        cin >> color[i];
        color[i]--;
        //if(i == 1)cout << (1<<color[i]) << endl;
        cnt[i][1<<color[i]]++;
    }
    for(int i(0); i < m;i++){
        int a,b; cin >> a >> b;
        a--;b--;
        if(color[a] == color[b])continue;
        //cout << "good " << a+1 << ' ' << b+1 << endl;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<st> qwe;
    for(int i(0); i < (1<<k);i++){
        if(get_cnt(i) == 1)continue;
        qwe.push_back({i,get_cnt(i)});
    }
    sort(qwe.begin(),qwe.end());
    //cout << "w " << cnt[1][2] << endl;
    for(int i(0); i < qwe.size();i++){
        solve(qwe[i].mask);
    }
    int ans = 0;
    for(int i(0); i < n;i++){
        for(int j(0); j < qwe.size();j++){
            ans+=cnt[i][qwe[j].mask];
            /*if(i == 0){
                cout << qwe[j].mask << ' ' << cnt[i][qwe[j].mask] << " = ";
                print_mask(qwe[j].mask);
                cout << endl;
            }*/
        }
    }
    cout << ans;
    return 0;
}
/*
*/

Compilation message

paths.cpp: In function 'void solve(long long int)':
paths.cpp:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j(0);j < v[i].size();j++){
                      ~~^~~~~~~~~~~~~
paths.cpp: At global scope:
paths.cpp:61:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
paths.cpp: In function 'int main()':
paths.cpp:87:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i(0); i < qwe.size();i++){
                   ~~^~~~~~~~~~~~
paths.cpp:92:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j(0); j < qwe.size();j++){
                       ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 9200 KB Output is correct
2 Correct 73 ms 5980 KB Output is correct
3 Correct 361 ms 93988 KB Output is correct
4 Correct 129 ms 14360 KB Output is correct
5 Correct 82 ms 10124 KB Output is correct
6 Correct 274 ms 65516 KB Output is correct
7 Correct 360 ms 93896 KB Output is correct
8 Correct 357 ms 94328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 99 ms 9200 KB Output is correct
12 Correct 73 ms 5980 KB Output is correct
13 Correct 361 ms 93988 KB Output is correct
14 Correct 129 ms 14360 KB Output is correct
15 Correct 82 ms 10124 KB Output is correct
16 Correct 274 ms 65516 KB Output is correct
17 Correct 360 ms 93896 KB Output is correct
18 Correct 357 ms 94328 KB Output is correct
19 Correct 99 ms 8608 KB Output is correct
20 Correct 73 ms 6064 KB Output is correct
21 Correct 361 ms 93916 KB Output is correct
22 Correct 132 ms 14304 KB Output is correct
23 Correct 81 ms 10164 KB Output is correct
24 Correct 260 ms 65544 KB Output is correct
25 Correct 351 ms 93868 KB Output is correct
26 Correct 353 ms 94428 KB Output is correct
27 Correct 83 ms 9208 KB Output is correct
28 Correct 139 ms 10844 KB Output is correct
29 Correct 489 ms 97776 KB Output is correct
30 Correct 323 ms 53712 KB Output is correct
31 Correct 341 ms 54296 KB Output is correct
32 Correct 484 ms 97804 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 380 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 29 ms 3320 KB Output is correct
3 Correct 26 ms 3320 KB Output is correct
4 Correct 99 ms 32504 KB Output is correct
5 Correct 87 ms 33008 KB Output is correct
6 Correct 211 ms 32900 KB Output is correct
7 Correct 27 ms 3320 KB Output is correct
8 Correct 134 ms 32760 KB Output is correct
9 Correct 98 ms 33008 KB Output is correct
10 Correct 132 ms 34032 KB Output is correct
11 Correct 92 ms 17776 KB Output is correct
12 Correct 128 ms 25936 KB Output is correct
13 Correct 95 ms 18288 KB Output is correct
14 Correct 184 ms 32860 KB Output is correct
15 Correct 198 ms 32888 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 476 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct