답안 #778427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778427 2023-07-10T10:12:36 Z vjudge1 Deblo (COCI18_deblo) C++17
0 / 90
109 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2
int dizi[100005],n,cev=0;
vector <int> v[100005];
int dp[100005][35][2];

//// left-shifting an integer “a” with an integer “b” denoted as ‘(a<<b)’ is equivalent to multiplying a with 2^b
//// right-shifting an integer “a” with an integer “b” denoted as ‘(a>>b)‘ is equivalent to dividing a with 2^b.
//// a=a/(2^b)

inline int fast(int x,int y){
    int ans=1;
    x%=mod;
    while(y!=0){
        if(y&1!=0)ans*=x;
        x*=x;
        y>>=1;
    }
    return ans;
}

inline int bit(int x,int y){

}

inline void dfs(int node,int ata){
    for(int i=0;i<32;i++) {
        if((dizi[node]>>i)%2==1)dp[node][i][1]=1;
        else dp[node][i][0]=1;
    }
    /*for(int i=0;i<20;i++){
        cout<<dp[node][i][0]<<" "<<dp[node][i][1]<<endl;
    }*/
    for(int i=0;i<v[node].size();i++){
        int go=v[node][i];
        if(go==ata)continue;
        dfs(go,node);
        for(int j=0;j<32;j++){
            int l=dp[go][j][1];
            int r=dp[go][j][0];
            int hu=max(l*dp[node][j][0],r*dp[node][j][1]);
            //cev+=hu;//
            cev+=(hu<<j);
           /* int gec=(hu<<j);
            cout<<gec<<endl;*/
            int k=(dizi[node]>>j)&1;
            //cout<<k<<endl;
            dp[node][j][k]+=r;
            dp[node][j][k^1]+=l;
            //cout<<dp[node][j][k]<<" "<<dp[node][j][k^1]<<endl;
        }
    }
}

int32_t main(){
    faster
    cin>>n;
    int c=0;
    for(int i=1;i<=n;i++){
        cin>>dizi[i];
        cev+=dizi[i];
    }
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,-1);
    cout<<cev<<'\n';
    return 0;
}

Compilation message

deblo.cpp: In function 'long long int fast(long long int, long long int)':
deblo.cpp:20:15: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   20 |         if(y&1!=0)ans*=x;
      |              ~^~~
deblo.cpp: In function 'long long int bit(long long int, long long int)':
deblo.cpp:29:1: warning: no return statement in function returning non-void [-Wreturn-type]
   29 | }
      | ^
deblo.cpp: In function 'void dfs(long long int, long long int)':
deblo.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(int i=0;i<v[node].size();i++){
      |                 ~^~~~~~~~~~~~~~~
deblo.cpp: In function 'int32_t main()':
deblo.cpp:63:9: warning: unused variable 'c' [-Wunused-variable]
   63 |     int c=0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2684 KB Output isn't correct
2 Incorrect 1 ms 2684 KB Output isn't correct
3 Incorrect 2 ms 2684 KB Output isn't correct
4 Incorrect 2 ms 3284 KB Output isn't correct
5 Incorrect 2 ms 3284 KB Output isn't correct
6 Runtime error 64 ms 65536 KB Execution killed with signal 9
7 Runtime error 58 ms 65536 KB Execution killed with signal 9
8 Incorrect 78 ms 65348 KB Output isn't correct
9 Incorrect 72 ms 64552 KB Output isn't correct
10 Incorrect 109 ms 63720 KB Output isn't correct