Submission #775491

#TimeUsernameProblemLanguageResultExecution timeMemory
775491YassineBenYounesKoala Game (APIO17_koala)C++17
37 / 100
42 ms464 KiB
#include "koala.h" #include<bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update> using namespace __gnu_pbds; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM) int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1}; int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1}; #define endl "\n" #define ss second #define ff first #define all(x) (x).begin() , (x).end() #define pb push_back #define vi vector<int> #define vii vector<pair<int,int>> #define vl vector<ll> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> #define vdd vector<pdd> #define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } const int mx = 105; int B[mx], R[mx]; /* int secret[mx]; int n; int ans = 0; void playRound(int *B, int *R){ ans++; int W = n; vii v; for(int i = 0; i < n;i++){ //cout << B[i] << " "; v.pb({secret[i], i}); } //cout << endl; sort(all(v), greater<pii>()); for(int i = 0; W > 0 && i < n;i++){ int ind = v[i].ss; if(W >= B[ind]+1){ W -= B[ind]+1; R[ind] = B[ind]+1; } else break; } for(int i = 0; i < n;i++){ //cout << R[i] << " "; } //cout << endl; } */ int minValue(int n, int W) { B[0] = 1; playRound(B, R); for(int i = 1; i < n;i++){ if(R[i] == 0)return i; } return 0; } int maxValue(int n, int W) { set<int> possible; for(int i = 0; i < n;i++){ possible.insert(i); } while(possible.size() > 1){ memset(R, 0, sizeof R); memset(B, 0, sizeof B); int k = W / possible.size(); for(int x : possible){ B[x] = k; } playRound(B, R); int l = 0; for(int i = 0; i < n;i++){ l = max(l, R[i]); } for(int i = 0; i < n;i++){ if(R[i] != l)possible.erase(i); } } return (*possible.begin()); } int greaterValue(int N, int W) { int l = 1, r = 14; while(l <= r){ int md = (l+r)/2; memset(R, 0, sizeof R); B[0] = B[1] = md; playRound(B, R); if(R[0] > R[1])return 0; if(R[1] > R[0])return 1; if(R[0] == 0){ r = md-1; } else{ l = md+1; } } return 0; } void allValues(int n, int W, int *P) { if (W == 2*n) { int cur = n; vector<bool> vis(n+5, 0); int tot = W; while(cur >= 1){ set<int> possible; for(int i = 0; i < n;i++){ if(vis[i])continue; possible.insert(i); } while(possible.size() > 1){ memset(R, 0, sizeof R); memset(B, 0, sizeof B); int k = tot / possible.size(); for(int x : possible){ B[x] = k; } playRound(B, R); int l = 0; for(int i = 0; i < n;i++){ if(vis[i])continue; l = max(l, R[i]); } for(int i = 0; i < n;i++){ if(vis[i])continue; if(R[i] != l)possible.erase(i); } } int ind = (*possible.begin()); P[ind] = cur; vis[ind] = 1; cur--; tot--; } } else{ int cur = n; vector<bool> vis(n, 0); memset(P, 0, sizeof P); int tot = W; while(cur >= 1){ set<int> possible; for(int i = 0; i < n;i++){ if(vis[i])continue; possible.insert(i); } int stop = 0; while(possible.size() > 1){ stop++; assert(stop <= 105); memset(R, 0, sizeof R); memset(B, 0, sizeof B); int k = tot / possible.size(); for(int x : possible){ B[x] = k; } playRound(B, R); int l = 0; for(int i = 0; i < n;i++){ if(vis[i])continue; l = max(l, R[i]); } for(int i = 0; i < n;i++){ if(vis[i])continue; if(R[i] != l)possible.erase(i); } } int ind = (*possible.begin()); P[ind] = cur; vis[ind] = 1; cur--; tot--; } } } /* int P[mx]; void run_case(){ n = 100; for(int i = 0; i < n;i++){ secret[i] = i+1; } allValues(n, n, P); cout << ans << endl; for(int i = 0; i < n;i++){ cout << P[i] << " "; } cout << endl; } int main(){ init(); speed; int t; //cin >> t; t = 1; while(t--){ run_case(); } }*/

Compilation message (stderr)

koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:165:22: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
  165 |         memset(P, 0, sizeof P);
      |                      ^~~~~~~~
koala.cpp: In function 'void init()':
koala.cpp:34:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:36:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...