Submission #538353

# Submission time Handle Problem Language Result Execution time Memory
538353 2022-03-16T16:02:34 Z fcw Happiness (Balkan15_HAPPINESS) C++17
Compilation error
0 ms 0 KB
#include "happiness.h"
#include <bits/stdc++.h>

using namespace std;
multiset<lint>s[40];
lint sum[40];

void add(lint x, int b){
	int p = 0;
	while(1ll<<(p+1) <= x) p++;
	if(b == 1) s[p].insert(x), sum[p] += x;
	else s[p].erase(s[p].find(x)), sum[p] -= x;
}

bool ok(){
	lint cnt = 0;
	for(int i=0;i<40;i++){
		if(s[i].empty()) continue;
		lint x = *s[i].begin();
		if(cnt + 1 < x) return 0;
		if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
		cnt += sum[i];
	}
	return 1;
}

bool init(int coinsCount, lint maxCoinSize, lint coins[]) {
	for(int i=0;i<coinsCount;i++) add(coins[i], 1);
	return ok();
}

bool is_happy(int event, int coinsCount, lint coins[]){
	for(int i=0;i<coinsCount;i++){
		if(event == -1) add(coins[i], -1);
		else add(coins[i], 1);
	}
	return ok();
}

Compilation message

happiness.cpp:5:10: error: 'lint' was not declared in this scope; did you mean 'uint'?
    5 | multiset<lint>s[40];
      |          ^~~~
      |          uint
happiness.cpp:5:14: error: template argument 1 is invalid
    5 | multiset<lint>s[40];
      |              ^
happiness.cpp:5:14: error: template argument 2 is invalid
happiness.cpp:5:14: error: template argument 3 is invalid
happiness.cpp:6:1: error: 'lint' does not name a type; did you mean 'uint'?
    6 | lint sum[40];
      | ^~~~
      | uint
happiness.cpp:8:6: error: variable or field 'add' declared void
    8 | void add(lint x, int b){
      |      ^~~
happiness.cpp:8:10: error: 'lint' was not declared in this scope; did you mean 'uint'?
    8 | void add(lint x, int b){
      |          ^~~~
      |          uint
happiness.cpp:8:18: error: expected primary-expression before 'int'
    8 | void add(lint x, int b){
      |                  ^~~
happiness.cpp: In function 'bool ok()':
happiness.cpp:16:2: error: 'lint' was not declared in this scope; did you mean 'uint'?
   16 |  lint cnt = 0;
      |  ^~~~
      |  uint
happiness.cpp:18:11: error: request for member 'empty' in 's[i]', which is of non-class type 'int'
   18 |   if(s[i].empty()) continue;
      |           ^~~~~
happiness.cpp:19:7: error: expected ';' before 'x'
   19 |   lint x = *s[i].begin();
      |       ^~
      |       ;
happiness.cpp:20:6: error: 'cnt' was not declared in this scope; did you mean 'int'?
   20 |   if(cnt + 1 < x) return 0;
      |      ^~~
      |      int
happiness.cpp:20:16: error: 'x' was not declared in this scope
   20 |   if(cnt + 1 < x) return 0;
      |                ^
happiness.cpp:21:11: error: request for member 'size' in 's[i]', which is of non-class type 'int'
   21 |   if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
      |           ^~~~
happiness.cpp:21:25: error: 'cnt' was not declared in this scope; did you mean 'int'?
   21 |   if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
      |                         ^~~
      |                         int
happiness.cpp:21:31: error: 'x' was not declared in this scope
   21 |   if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
      |                               ^
happiness.cpp:21:50: error: request for member 'begin' in 's[i]', which is of non-class type 'int'
   21 |   if(s[i].size() > 1 && cnt + x + 1 < *next(s[i].begin())) return 0;
      |                                                  ^~~~~
happiness.cpp:22:3: error: 'cnt' was not declared in this scope; did you mean 'int'?
   22 |   cnt += sum[i];
      |   ^~~
      |   int
happiness.cpp:22:10: error: 'sum' was not declared in this scope
   22 |   cnt += sum[i];
      |          ^~~
happiness.cpp: At global scope:
happiness.cpp:27:27: error: 'lint' has not been declared
   27 | bool init(int coinsCount, lint maxCoinSize, lint coins[]) {
      |                           ^~~~
happiness.cpp:27:45: error: 'lint' has not been declared
   27 | bool init(int coinsCount, lint maxCoinSize, lint coins[]) {
      |                                             ^~~~
happiness.cpp: In function 'bool init(int, int, int*)':
happiness.cpp:28:32: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   28 |  for(int i=0;i<coinsCount;i++) add(coins[i], 1);
      |                                ^~~
      |                                std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from happiness.cpp:2:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
happiness.cpp: At global scope:
happiness.cpp:32:42: error: 'lint' has not been declared
   32 | bool is_happy(int event, int coinsCount, lint coins[]){
      |                                          ^~~~
happiness.cpp: In function 'bool is_happy(int, int, int*)':
happiness.cpp:34:19: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   34 |   if(event == -1) add(coins[i], -1);
      |                   ^~~
      |                   std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from happiness.cpp:2:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
happiness.cpp:35:8: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   35 |   else add(coins[i], 1);
      |        ^~~
      |        std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from happiness.cpp:2:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~