Submission #704028

# Submission time Handle Problem Language Result Execution time Memory
704028 2023-03-01T11:50:48 Z vjudge1 Bank (IZhO14_bank) C++17
19 / 100
56 ms 716 KB
// Problem: Elevator Rides

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std ;

#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ones(x) __builtin_popcount(x)
#define remove(v)  v.erase(unique(all(v)), v.end())
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)

#ifdef local
#include "C:\debug.h"
#else
#define dbg(x...) 42
#endif
#define int long long

const int N = 2e6 + 2 ;
const int MOD = 1e9 + 7 ;
const int P = 1007 ;

int n , m , a[21] , b[21] , p[21] ;
int dp[1048577] ;

void solve(){
    p[0] = 1 ;
    rep(i , 1 , 20) p[i] = p[i - 1] * P , p[i] %= MOD ;
    cin >> n >> m ;
    int hash = 0 ;
    rep(i , 1 , n) cin >> a[i] ;
    sort(a + 1 , a + 1 + n) ;
    rep(i , 1 , n) {
        int cur = (a[i] * (p[i] % MOD)) % MOD ;
        hash += cur ; hash %= MOD ;
    }
    set<int> w(a + 1 , a + 1 + n) ;
    rep(i , 1 , m) cin >> b[i] ;
    set<pair<int,int>> e ;
    rep(i , 1 , (1 << m) - 1) {
        int cur = 0 ;
        rep(mask , 0 , m - 1) {
            if((i >> mask) & 1) {
                cur += b[mask + 1] ;
            }
        }
        if(cur <= 1000 && w.count(cur)) e.insert({i , cur}) ;
    }
    vector<pair<int,int>> item(all(e)) ;
    int sz = sz(item) ;
    rep(i , 0 , (1 << sz) - 1) {
        vector<int> v ;
        int cur = 0 ;
        bool ok = 1 ;
        rep(mask , 0 , sz - 1) {
            if((i >> mask & 1)) {
                int x = ones(cur) ;
                int y = ones(item[mask].first) ;
                cur ^= item[mask].first ;
                if(x + y != ones(cur)) {
                    ok = 0 ;
                    break ;
                }
                v.pb(item[mask].second) ;
            }
        }
        sort(all(v)) ;
        int H = 0 , id = 0 ;
        for(auto& x : v) {
            id++ ;
            int add = (x * (p[id] % MOD)) % MOD ;
            H += add ; H %= MOD ;
        }
        if(H == hash) {
            cout << "YES\n" ;
            return ;
        }
    }
    cout << "NO\n" ;
}

signed main () {
	// ios::sync_with_stdio(false) ;
	// cin.tie(0) ;
	int test = 1 ;
	// cin >> test ; 
	for(int i = 1 ; i <= test ; i++) {
		solve() ;
	}
}

Compilation message

bank.cpp: In function 'void solve()':
bank.cpp:63:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   63 |         bool ok = 1 ;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 224 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 55 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 55 ms 716 KB Output is correct
9 Correct 56 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 224 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 55 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 55 ms 716 KB Output is correct
9 Correct 56 ms 212 KB Output is correct
10 Incorrect 34 ms 316 KB Output isn't correct
11 Halted 0 ms 0 KB -