Submission #340074

#TimeUsernameProblemLanguageResultExecution timeMemory
340074emil_physmathBank (IZhO14_bank)C++17
100 / 100
571 ms16320 KiB
#include <algorithm> #include <iostream> #include <cstring> #include <vector> #include <set> using namespace std; typedef double ldouble; typedef long long llong; typedef unsigned int uint; vector<uint> sumup[1001]; int sum[1 << 20], bits[1 << 20]; bool ok[1 << 20]; bool IsSet(uint mask, uint i) { return mask & (1 << i); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n); for (int& x: a) cin >> x; vector<int> b(m); for (int& x: b) cin >> x; for (uint mask = 0; mask < (1 << m); ++mask) { int curSum = 0, curBits = 0; for (int i = 0; i < m; ++i) if (IsSet(mask, i)) { ++curBits; curSum += b[i]; } if (curSum <= 1000) sumup[curSum].push_back(mask); sum[mask] = curSum; bits[mask] = curBits; } vector<uint> possLeft; possLeft.push_back((1 << m) - 1); for (int i = 0; i < n; ++i) { for (uint mask = 0; mask < (1 << m); ++mask) ok[mask] = false; for (uint left: possLeft) { /*if ((1 << bits[left]) < sumup[a[i]].size()) { for(uint mask = left; mask; mask = (mask - 1) & left) if (sum[mask] == a[i]) ok[left ^ mask] = true; } else {*/ for (uint mask: sumup[a[i]]) if ((mask & left) == mask) ok[left ^ mask] = true; //} } possLeft.clear(); for (uint mask = 0; mask < (1 << m); ++mask) if (ok[mask]) possLeft.push_back(mask); } // cerr << possLeft.size() << endl; cout << (possLeft.size() ? "YES" : "NO"); }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:33:30: warning: comparison of integer expressions of different signedness: 'uint' {aka 'unsigned int'} and 'int' [-Wsign-compare]
   33 |     for (uint mask = 0; mask < (1 << m); ++mask)
      |                         ~~~~~^~~~~~~~~~
bank.cpp:51:34: warning: comparison of integer expressions of different signedness: 'uint' {aka 'unsigned int'} and 'int' [-Wsign-compare]
   51 |         for (uint mask = 0; mask < (1 << m); ++mask)
      |                             ~~~~~^~~~~~~~~~
bank.cpp:69:34: warning: comparison of integer expressions of different signedness: 'uint' {aka 'unsigned int'} and 'int' [-Wsign-compare]
   69 |         for (uint mask = 0; mask < (1 << m); ++mask)
      |                             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...