Submission #2485002


Source Code Expand

#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <assert.h>

#define rep(i, a) for (int i = 0; i < (a); i++)

using namespace std;

template<typename T>
class Dp1d {
public:
  Dp1d(int n, T v) :
    size(n), default_value(v) {
    dp = new T[size];
  }
  ~Dp1d() {
    delete [] dp;
  }
  
  void init(T value) {
    for (int i = 0; i < size; i++) {
      set(i, value);
    }
  }
  
  T& operator[](size_t index) { return dp[index]; }
  
  T get(int i) { 
    if (i < 0 || i >= size) return default_value;
    return dp[i]; 
  }
  void set(int i, T value) { dp[i] = value; }
  
  string str(int i) { return "dp[" + to_string(i) + "]=" + to_string(get(i)); }

private:  
  int size;
  T default_value;
  T* dp;
};

template<typename T>
class Dp2d {
public:
  Dp2d(int r, int c, T v) :
    row(r), col(c), default_value(v) {
    dp = new T[r*c];
  }
  ~Dp2d() {
    delete [] dp;
  }

  void init(T value) {
    for (int r = 0; r < row; r++) {
      for (int c = 0; c < col; c++) {
	set(r, c, value);
      }
    }
  }

  T* operator[](size_t index) { return &dp[index*col]; }
  const T* operator[](size_t index) const { return &dp[index*col]; }
  
  T get(int r, int c) { 
    if (r < 0 || r >= row || c < 0 || c >= col) return default_value;
    return dp[r*col+c]; 
  }
  void set(int r, int c, T value) { 
    assert(0 <= r && r < row);
    assert(0 <= c && c < col);
    dp[r*col+c] = value; 
  }

  string str(int r, int c) { return "dp[" + to_string(r) + "][" + to_string(c) + "]=" + to_string(get(r,c)); }
  void print(int r, int c) { cout << "dp[" << to_string(r) << "][" << to_string(c) << "]=" << to_string(get(r,c)) << endl; }

private:  
  int row;
  int col;
  T default_value;
  T* dp;
};

class Company {
public:
  Company(int a_, int b_, int c_, int s_)
    : a(a_), b(b_), c(c_), salary(s_) {}

  bool operator<(const Company& other) {
    return salary < other.salary;
  }
  
  int a;
  int b;
  int c;
  int salary;
};

class Person {
public:
  Person(int a_, int b_, int c_)
    : a(a_), b(b_), c(c_) {}
  
  int a;
  int b;
  int c;
};

int indeed(vector<Company>& cs, Person& p)
{
  for (int i = 0; i < cs.size(); i++) {
    Company c = cs[i];
    if (p.a >= c.a && p.b >= c.b && p.c >= c.c) {
      return c.salary;
    }
  }
  return 0;
}

int main()
{
  int n, m;
  cin >> n >> m;

  vector<Company> cs;
  for (int i = 0; i < n; i++) {
    int a, b, c, w;
    cin >> a >> b >> c >> w;
    cs.push_back(Company(a, b, c, w));
  }

  struct {
    bool operator()(Company& a, Company& b) const
    {   
      return a.salary > b.salary;
    }   
  } salaryGreater;
  sort(cs.begin(), cs.end(), salaryGreater);
  
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    Person p(x, y, z);

    cout << indeed(cs, p) << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task C - Optimal Recommendations
User masateruk
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3081 Byte
Status TLE
Exec Time 2103 ms
Memory 1652 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 23
TLE × 1
Set Name Test Cases
All 10-random-00.txt, 10-random-01.txt, 10-random-02.txt, 10-random-03.txt, 10-random-04.txt, 20-absW-00.txt, 20-absW-01.txt, 20-absW-02.txt, 20-absW-03.txt, 20-absW-04.txt, 30-balance-00.txt, 30-balance-01.txt, 30-balance-02.txt, 30-balance-03.txt, 30-balance-04.txt, 40-limit_dim-00.txt, 40-limit_dim-01.txt, 40-limit_dim-02.txt, 40-limit_dim-03.txt, 40-limit_dim-04.txt, 40-limit_dim-05.txt, 40-limit_dim-06.txt, Corner1.txt, Sample1.txt
Case Name Status Exec Time Memory
10-random-00.txt AC 175 ms 1652 KB
10-random-01.txt AC 1 ms 256 KB
10-random-02.txt AC 86 ms 640 KB
10-random-03.txt AC 124 ms 1016 KB
10-random-04.txt AC 54 ms 1400 KB
20-absW-00.txt TLE 2103 ms 1400 KB
20-absW-01.txt AC 1 ms 256 KB
20-absW-02.txt AC 1138 ms 1400 KB
20-absW-03.txt AC 1791 ms 892 KB
20-absW-04.txt AC 314 ms 640 KB
30-balance-00.txt AC 179 ms 1652 KB
30-balance-01.txt AC 1 ms 256 KB
30-balance-02.txt AC 47 ms 512 KB
30-balance-03.txt AC 93 ms 1400 KB
30-balance-04.txt AC 115 ms 896 KB
40-limit_dim-00.txt AC 177 ms 1652 KB
40-limit_dim-01.txt AC 169 ms 1652 KB
40-limit_dim-02.txt AC 172 ms 1652 KB
40-limit_dim-03.txt AC 169 ms 1652 KB
40-limit_dim-04.txt AC 169 ms 1652 KB
40-limit_dim-05.txt AC 169 ms 1652 KB
40-limit_dim-06.txt AC 167 ms 1652 KB
Corner1.txt AC 1 ms 256 KB
Sample1.txt AC 1 ms 256 KB