Submission #342893

#TimeUsernameProblemLanguageResultExecution timeMemory
342893chonTreasure (different grader from official contest) (CEOI13_treasure2)C++14
Compilation error
0 ms0 KiB
#include "treasure.h" #include <bits/stdc++.h> using namespace std; //#define pb push_back //#define ii pair<int,int> typedef struct { int key[4]; unsigned long data; }Hash; Hash tb[MAX_TABLE]; unsigned long hash(const char *str) { unsigned long hash = 5381; int c; while (c = *str++) { hash = (((hash << 5) + hash) + c) % MAX_TABLE; } return hash % MAX_TABLE; } int find(const char *key, char *data) { unsigned long h = hash(key); int cnt = MAX_TABLE; while (tb[h].key[0] != 0 && cnt--) { if (strcmp(tb[h].key, key) == 0) { strcpy(data, tb[h].data); return 1; } h = (h + 1) % MAX_TABLE; } return 0; } int add(const char *key, char *data) { unsigned long h = hash(key); while (tb[h].key[0] != 0) { if (strcmp(tb[h].key, key) == 0) { return 0; } h = (h + 1) % MAX_TABLE; } strcpy(tb[h].key, key); strcpy(tb[h].data, data); return 1; } int ans[105][105]; int HOR[105], VER[105]; int area, included, line, ri, le; //map< tuple<int, int, int, int>, int > dp; int askit(int r1, int c1, int r2, int c2){ tuple<int,int,int,int> tup(r1, c1, r2, c2); if (dp.find(tup) != dp.end() ) return dp[tup]; return dp[tup] = countTreasure(r1, c1, r2, c2); } int f(vector< pair<int,int> > v, int r, int c, int N){ int result = 0, knew = 0, red = 0, want = 0; if (v[3].second == 'A'){ for (int i=1; i<=r-1; i++){ for (int j=1; j<=c; j++){ knew += ans[i][j]; } } red = askit(1, 1, r, c); want = red - knew; knew = 0; for (int j=1; j<=c - 1; j++) knew += ans[r][j]; result = want - knew; }else if (v[3].second == 'B'){ for (int i=1; i<=r-1; i++){ for (int j=c+1; j<=N; j++){ knew += ans[i][j]; } } if (c+1 <= N) red = askit(1, c+1, r, N); want = red - knew; result = included - want; }else if (v[3].second == 'C'){ for (int i=1; i<=r-1; i++){ for (int j=c+1; j<=N; j++){ knew += ans[i][j]; } } knew = ri - knew; if (c+1 <= N && r+1 <= N) red = askit(r+1, c+1, N, N); want = knew - red; result = included - want; }else{ // D for (int i=1; i<=r-1; i++){ for (int j=1; j<=c; j++){ knew += ans[i][j]; } } knew = le - knew; if (r+1 <= N) red = askit(r+1, 1, N, c); want = knew - red; knew = 0; for (int j=1; j<=c - 1; j++) knew += ans[r][j]; result = want - knew; } return result; } void findTreasure (int N) { //int cnt = countTreasure(1, 1, N, N); //if(cnt > 0) Report (1, 1); area = askit(1, 1, N, N); for (int i=1; i<=N - 1; i++){ if ( i > (N-i) ) VER[i] = askit(1, 1, i, N); else VER[i] = area - askit(i+1, 1, N, N); } for (int i=1; i<=N - 1; i++){ if ( i > (N-i) ) HOR[i] = askit(1, 1, N, i); else HOR[i] = area - askit(1, i+1, N, N); } VER[N] = HOR[N] = area; for (int i=1; i<=N; i++){ for (int j=1; j<=N; j++){ int below = VER[N] - VER[i]; int sup = VER[i-1]; line = area - sup - below; included = line; for (int k=1; k<j; k++) included -= ans[i][k]; ri = HOR[N] - HOR[j]; le = HOR[j]; vector< pair<int, int> > srt; int dx, dy; dx = j, dy = i; srt.pb(ii(dx*dy, 'A')); dx = N - j, dy = i; srt.pb(ii(dx*dy, 'B')); dx = N - j, dy = N - i; srt.pb(ii(dx*dy, 'C')); dx = j, dy = N - i; srt.pb(ii(dx*dy, 'D')); sort(srt.begin(), srt.end()); ans[i][j] = f(srt, i, j, N); } } for (int i=1; i<=N; i++){ for (int j=1; j<=N; j++){ if (ans[i][j]) Report(i,j); } } }

Compilation message (stderr)

treasure.cpp:14:9: error: 'MAX_TABLE' was not declared in this scope
   14 | Hash tb[MAX_TABLE];
      |         ^~~~~~~~~
treasure.cpp: In function 'long unsigned int hash(const char*)':
treasure.cpp:21:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   21 |     while (c = *str++)
      |            ~~^~~~~~~~
treasure.cpp:23:45: error: 'MAX_TABLE' was not declared in this scope
   23 |         hash = (((hash << 5) + hash) + c) % MAX_TABLE;
      |                                             ^~~~~~~~~
treasure.cpp:26:19: error: 'MAX_TABLE' was not declared in this scope
   26 |     return hash % MAX_TABLE;
      |                   ^~~~~~~~~
treasure.cpp: In function 'int find(const char*, char*)':
treasure.cpp:31:23: error: reference to 'hash' is ambiguous
   31 |     unsigned long h = hash(key);
      |                       ^~~~
In file included from /usr/include/c++/9/bits/basic_string.h:6719,
                 from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from treasure.cpp:2:
/usr/include/c++/9/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
treasure.cpp:16:15: note:                 'long unsigned int hash(const char*)'
   16 | unsigned long hash(const char *str)
      |               ^~~~
treasure.cpp:32:15: error: 'MAX_TABLE' was not declared in this scope
   32 |     int cnt = MAX_TABLE;
      |               ^~~~~~~~~
treasure.cpp:34:12: error: 'tb' was not declared in this scope; did you mean 'tm'?
   34 |     while (tb[h].key[0] != 0 && cnt--)
      |            ^~
      |            tm
treasure.cpp: In function 'int add(const char*, char*)':
treasure.cpp:48:23: error: reference to 'hash' is ambiguous
   48 |     unsigned long h = hash(key);
      |                       ^~~~
In file included from /usr/include/c++/9/bits/basic_string.h:6719,
                 from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from treasure.cpp:2:
/usr/include/c++/9/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
treasure.cpp:16:15: note:                 'long unsigned int hash(const char*)'
   16 | unsigned long hash(const char *str)
      |               ^~~~
treasure.cpp:50:12: error: 'tb' was not declared in this scope; did you mean 'tm'?
   50 |     while (tb[h].key[0] != 0)
      |            ^~
      |            tm
treasure.cpp:57:23: error: 'MAX_TABLE' was not declared in this scope
   57 |         h = (h + 1) % MAX_TABLE;
      |                       ^~~~~~~~~
treasure.cpp:59:12: error: 'tb' was not declared in this scope; did you mean 'tm'?
   59 |     strcpy(tb[h].key, key);
      |            ^~
      |            tm
treasure.cpp: In function 'int askit(int, int, int, int)':
treasure.cpp:73:6: error: 'dp' was not declared in this scope
   73 |  if (dp.find(tup) != dp.end() ) return dp[tup];
      |      ^~
treasure.cpp:74:9: error: 'dp' was not declared in this scope
   74 |  return dp[tup] = countTreasure(r1, c1, r2, c2);
      |         ^~
treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:158:8: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
  158 |    srt.pb(ii(dx*dy, 'A'));
      |        ^~
treasure.cpp:158:11: error: 'ii' was not declared in this scope; did you mean 'i'?
  158 |    srt.pb(ii(dx*dy, 'A'));
      |           ^~
      |           i
treasure.cpp:160:8: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
  160 |    srt.pb(ii(dx*dy, 'B'));
      |        ^~
treasure.cpp:162:8: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
  162 |    srt.pb(ii(dx*dy, 'C'));
      |        ^~
treasure.cpp:164:8: error: 'class std::vector<std::pair<int, int> >' has no member named 'pb'
  164 |    srt.pb(ii(dx*dy, 'D'));
      |        ^~