답안 #775476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775476 2023-07-06T12:27:12 Z vjudge1 코알라 (APIO17_koala) C++17
37 / 100
78 ms 356 KB
#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;
void playRound(int *B, int *R){
    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+5, 0);
        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 = cur / 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--;
        }
    }
}

//int P[mx];
/*
void run_case(){
    n = 10;
    secret[0] = 2;
    secret[1] = 1;
    secret[2] = 3;
    secret[3] = 5;
    secret[4] = 7;
    secret[5] = 4;
    secret[6] = 8;
    secret[7] = 6;
    secret[8] = 9;
    secret[9] = 10;
    allValues(10, 10, P);
    for(int i = 0; i < 10;i++){
        cout << P[i] << " ";
    }
    cout << endl;
}

int main(){
    init();
    speed;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        run_case();
    }
}*/

Compilation message

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);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
3 Correct 3 ms 208 KB Output is correct
4 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 12 ms 208 KB Output is correct
3 Correct 12 ms 324 KB Output is correct
4 Correct 12 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 328 KB Output is correct
2 Correct 40 ms 344 KB Output is correct
3 Correct 33 ms 336 KB Output is correct
4 Correct 34 ms 348 KB Output is correct
5 Correct 33 ms 344 KB Output is correct
6 Correct 34 ms 340 KB Output is correct
7 Correct 33 ms 340 KB Output is correct
8 Correct 33 ms 336 KB Output is correct
9 Correct 33 ms 356 KB Output is correct
10 Correct 34 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -