Submission #1380832
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; using ull = unsigned long long; using vvi = vector<vector<int>>; class Combinations{ // n 個の中から k 個を選ぶ組み合わせを列挙する ull S; ull E; public: Combinations(int n, int k):S((1ull << k) - 1ull), E(~((1ull << n) - 1ull)){} ull next(){ ull currentS = S; if (S & E) return 0ull; ull smallest = S & -S; ull ripple = S + smallest; ull nsmallest = ripple & -ripple; S = ripple | (((nsmallest / smallest) >> 1) - 1); return currentS; } }; int calc(int xmask, int M, int Q, const vvi &xyz){ vector<int> hs(M, 0); for (int g = 0; xmask; ++g, xmask >>= 1){ if (xmask & 1){ for (int b = 0; b != M; ++b){ hs[b] += xyz[g][b]; } } } sort(hs.begin(), hs.end(), greater<int>()); return accumulate(hs.begin(), hs.begin()+Q, 0); } int main() { int N, M, P, Q, R; cin >> N >> M >> P >> Q >> R; vvi xyz(N, vector<int>(M, 0)); for (int r = 0; r != R; ++r){ int x, y, z; cin >> x >> y >> z; xyz[x - 1][y - 1] = z; } int max_happiness = 0; Combinations cb(N, P); while (int xmask = cb.next()){ max_happiness = max(max_happiness, calc(xmask, M, Q, xyz)); } cout << max_happiness << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - バレンタインデー |
User | rpy3cpp |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1496 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int calc(int, int, int, const vvi&)’: ./Main.cpp:37:50: error: ‘accumulate’ was not declared in this scope return accumulate(hs.begin(), hs.begin()+Q, 0); ^