Submission #1178306


Source Code Expand

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int n, m, p, q, r;
vector<vvi> yz;
int ans;

vector<bool> calculated_girl;

int calculate_max_value(int girl) {
  vi value_of_boy(m, 0);
  rep (i, n) {
    if ((girl>>i)&1) {
      for (auto y_z : yz[i]) {
        value_of_boy[y_z[0]] += y_z[1];
      }
    }
  }
  sort(all(value_of_boy), greater<int>());
  int ret = 0;
  rep (i, q) {
    ret += value_of_boy[i];
  }
  return ret;
}

void dfs(int girl, int num_girl) {
  if (calculate_max_value[girl]) return;
  calculated_girl[girl] = true;

  if (num_girl == p) {
    ans = max(ans, calculate_max_value(girl));
    return;
  }
  rep (i, n) {
    if (((girl>>i)&1) == 0) {
      dfs(girl|(1<<i), num_girl+1);
    }
  }
}

void solve() {
  ans = 0;
  calculated_girl.assign(1<<n + 10, false);
  dfs(0, 0);
}

int main() {
  scanf("%d%d%d%d%d", &n, &m, &p, &q, &r);
  yz.resize(n);
  rep (i, r) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x -= 1;
    y -= 1;
    yz[x].push_back((vi){y, z});
  }

  solve();
  printf("%d\n", ans);

  return 0;
}

Submission Info

Submission Time
Task D - バレンタインデー
User tspcx
Language C++14 (Clang 3.8.0)
Score 0
Code Size 1930 Byte
Status CE

Compile Error

./Main.cpp:60:7: error: subscript of pointer to function type 'int (int)'
  if (calculate_max_value[girl]) return;
      ^~~~~~~~~~~~~~~~~~~
./Main.cpp:76:31: warning: operator '<<' has lower precedence than '+'; '+' will be evaluated first [-Wshift-op-parentheses]
  calculated_girl.assign(1<<n + 10, false);
                          ~~~~^~~~
./Main.cpp:76:31: note: place parentheses around the '+' expression to silence this warning
  calculated_girl.assign(1<<n + 10, false);
                              ^
                            (     )
1 warning and 1 error generated.