Submission #343117

#TimeUsernameProblemLanguageResultExecution timeMemory
343117chonTreasure (different grader from official contest) (CEOI13_treasure2)C++14
Compilation error
0 ms0 KiB
#include "treasure.h" #include <bits/stdc++.h> //여기서 부터 Hash 구현 #define MAX_TABLE 12960000 typedef struct { int key[4]; int data; }Hash; Hash tb[MAX_TABLE]; unsigned long Hash_Key(const int* str) { unsigned long hash = 5381; int c; c = *str; for (int i = 0; i < 4; i++) { hash = (((hash << 5) + hash) + c) % MAX_TABLE; *str++; c = *str; } return hash % MAX_TABLE; } int find(const int *key, int *data ) { unsigned long h = Hash_Key(key); int cnt = MAX_TABLE; while (tb[h].key[0] != 0 && cnt--) { if ( tb[h].key[0]==*key && tb[h].key[1]==*key+1 && tb[h].key[2]==*key+2 && tb[h].key[3]==*key+3 ) { *data=tb[h].data; return 1; } h = (h + 1) % MAX_TABLE; } return 0; } int add(const int *key, int *data) { unsigned long h = Hash_Key(key); while (tb[h].key[0] != 0) { if ( tb[h].key[0]==*key && tb[h].key[1]==*key+1 && tb[h].key[2]==*key+2 && tb[h].key[3]==*key+3) { return 0; } h = (h + 1) % MAX_TABLE; } tb[h].key[0]= *key; tb[h].key[1]= *key+1; tb[h].key[2]= *key+2; tb[h].key[3]= *key+3; tb[h].data= *data; return 1; } using namespace std; 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); int input[4]; input[0]=r1,input[1]=c1,input[2]=r2,input[3]=c2; int DATA; DATA=0; if (find(input, &DATA) == 1 ) return tb[ DATA].data; add(input, DATA); return dp[DATA].data = countTreasure(r1, c1, r2, c2); } int f(int v, int r, int c, int N) { int result = 0, knew = 0, red = 0, want = 0; if (v == 0) { 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 == 1) { 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 == 2) { 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; int data[4][2]; dx = j, dy = i; data[0][0] = dx * dy; data[0][1] = 0; dx = N - j, dy = i; data[1][0] = dx * dy; data[1][1] = 1; dx = N - j, dy = N - i; data[2][0] = dx * dy; data[2][1] = 2; dx = j, dy = N - i; data[3][0] = dx * dy; data[3][1] = 3; for (int a = 0; a < 4; a++) { for (int b = a + 1; b < 4; b++) { if (data[a][0] > data[b][0]) { int temp; temp = data[a][0]; data[a][0] = data[b][0]; data[b][0] = temp; temp = data[a][1]; data[a][1] = data[b][1]; data[b][1] = temp; } else if (data[a][0] == data[b][0] && data[a][1] > data[b][1]) { int temp; temp = data[a][0]; data[a][0] = data[b][0]; data[b][0] = temp; temp = data[a][1]; data[a][1] = data[b][1]; data[b][1] = temp; } } } ans[i][j] = f(data[3][1], 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: In function 'long unsigned int Hash_Key(const int*)':
treasure.cpp:27:3: warning: value computed is not used [-Wunused-value]
   27 |   *str++;
      |   ^~~~~~
treasure.cpp: In function 'int askit(int, int, int, int)':
treasure.cpp:96:15: error: invalid conversion from 'int' to 'int*' [-fpermissive]
   96 |    add(input, DATA);
      |               ^~~~
      |               |
      |               int
treasure.cpp:52:30: note:   initializing argument 2 of 'int add(const int*, int*)'
   52 | int add(const int *key, int *data)
      |                         ~~~~~^~~~
treasure.cpp:97:13: error: no match for 'operator[]' (operand types are 'std::map<std::tuple<int, int, int, int>, int>' and 'int')
   97 |    return dp[DATA].data = countTreasure(r1, c1, r2, c2);
      |             ^
In file included from /usr/include/c++/9/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from treasure.cpp:2:
/usr/include/c++/9/bits/stl_map.h:490:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::tuple<int, int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::tuple<int, int, int, int>]'
  490 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:490:34: note:   no known conversion for argument 1 from 'int' to 'const key_type&' {aka 'const std::tuple<int, int, int, int>&'}
  490 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_map.h:510:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::tuple<int, int, int, int>; _Tp = int; _Compare = std::less<std::tuple<int, int, int, int> >; _Alloc = std::allocator<std::pair<const std::tuple<int, int, int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::tuple<int, int, int, int>]'
  510 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:510:29: note:   no known conversion for argument 1 from 'int' to 'std::map<std::tuple<int, int, int, int>, int>::key_type&&' {aka 'std::tuple<int, int, int, int>&&'}
  510 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:244:2: error: expected '}' at end of input
  244 |  }
      |  ^
treasure.cpp:156:26: note: to match this '{'
  156 | void findTreasure(int N) {
      |                          ^