답안 #718107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718107 2023-04-03T10:41:10 Z vjudge1 코알라 (APIO17_koala) C++17
100 / 100
56 ms 476 KB
#include "koala.h"

#include <bits/stdc++.h>
using namespace std;
int n;
int B[110],R[110];
int minValue(int N, int W)
{
    n=N;
    fill_n(B,n,0);
    B[0] = 1;
    playRound(B,R);
    if (R[0]<=1) return 0;
    else for (int i=1; i<n; i++) if (R[i]==0)
        return i;
}

int maxValue(int N, int W)
{
    n=N;
    vector <int> tmp;
    for (int i=0; i<n; i++) tmp.push_back(i);
    while (tmp.size()!=1)
    {
        int val = W / (tmp.size());
        fill_n(B,n,0);
        for (int i:tmp) B[i] = val;
        playRound(B,R);
        tmp.clear();
        for (int i=0; i<n; i++) if (R[i]>val) tmp.push_back(i);
    }
    return tmp[0];
}

int greaterValue(int N, int W)
{
    n=N;
    fill_n(B,n,0);
    int l=1; int r=min(9,W/2);
    while (l<r)
    {
        int mid=(l+r)/2;
        B[0]=B[1]=mid;

        playRound(B,R);
        if (R[0]>mid&&R[1]>mid) l=mid+1;
        else if (R[0]<=mid&&R[1]<=mid) r=mid-1;
        else return (R[0]<R[1]);
    }
    B[0]=B[1]=l;
    playRound(B,R);
    return (R[0]<R[1]);
}

bool comp(int u, int v, int W)
{
    fill_n(B,n,0);
    B[u]=B[v]=W;
    playRound(B,R);
    return R[v]>W;
}

vector <int> msort(vector <int> v, int lx, int rx, int W)
{
    if (lx==rx) return v;
    int mid=(lx+rx)/2;
    vector <int> a,b;
    a.insert(a.end(),v.begin(),v.begin()+(mid-lx+1));
    b.insert(b.end(),v.begin()+(mid-lx+1),v.end());
    a=msort(a,lx,mid,W);
    b=msort(b,mid+1,rx,W);
    vector <int> res;
    int ita,itb;
    ita=itb=0;
    while (ita<a.size()&&itb<b.size())
    {
        if (comp(a[ita],b[itb],W)) res.push_back(a[ita++]);
        else res.push_back(b[itb++]);
    }
    res.insert(res.end(),a.begin()+ita,a.end());
    res.insert(res.end(),b.begin()+itb,b.end());
    return res;
}

void sub4(int N, int W, int *P)
{
    n=N;
    vector <int> tmp;
    for (int i=0; i<n; i++) tmp.push_back(i);
    tmp=msort(tmp,0,n-1,W/2);
    for (int i=0; i<n; i++) P[tmp[i]] = i+1;
}


void dnc(vector <int> v, int lx, int rx, int W, int *P)
{
    if (lx>rx) return;
    if (lx==rx)
    {
        P[v[0]]=lx+1;
        return;
    }
    int mid=(lx+rx)/2;
    int x = min(int(trunc(sqrt(2*(lx+1)))),W/(rx-lx+1));
    fill_n(B,n,0);
    for (int i:v) B[i]=x;
    playRound(B,R);
    vector <int> vl,vr;
    for (int i:v) if (R[i]<=x) vl.push_back(i);
    else vr.push_back(i);
    dnc(vl,lx,lx+vl.size()-1,W,P);
    dnc(vr,rx-vr.size()+1,rx,W,P);
}

void sub5(int N, int W, int *P)
{
    n=N;
    vector <int> tmp;
    for (int i=0; i<n; i++) tmp.push_back(i);
    dnc(tmp,0,n-1,W,P);
}

void allValues(int N, int W, int *P)
{
    if (W==2*N) sub4(N,W,P);
    else
        sub5(N,W,P);
}

Compilation message

koala.cpp: In function 'std::vector<int> msort(std::vector<int>, int, int, int)':
koala.cpp:75:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     while (ita<a.size()&&itb<b.size())
      |            ~~~^~~~~~~~~
koala.cpp:75:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     while (ita<a.size()&&itb<b.size())
      |                          ~~~^~~~~~~~~
koala.cpp: In function 'void dnc(std::vector<int>, int, int, int, int*)':
koala.cpp:103:9: warning: unused variable 'mid' [-Wunused-variable]
  103 |     int mid=(lx+rx)/2;
      |         ^~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type]
   16 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 6 ms 208 KB Output is correct
3 Correct 4 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 208 KB Output is correct
2 Correct 11 ms 208 KB Output is correct
3 Correct 12 ms 208 KB Output is correct
4 Correct 11 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 328 KB Output is correct
2 Correct 56 ms 324 KB Output is correct
3 Correct 46 ms 324 KB Output is correct
4 Correct 48 ms 332 KB Output is correct
5 Correct 47 ms 332 KB Output is correct
6 Correct 51 ms 340 KB Output is correct
7 Correct 47 ms 336 KB Output is correct
8 Correct 48 ms 328 KB Output is correct
9 Correct 50 ms 328 KB Output is correct
10 Correct 50 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 324 KB Output is correct
2 Correct 29 ms 208 KB Output is correct
3 Correct 29 ms 208 KB Output is correct
4 Correct 27 ms 208 KB Output is correct
5 Correct 27 ms 324 KB Output is correct
6 Correct 28 ms 208 KB Output is correct
7 Correct 27 ms 208 KB Output is correct
8 Correct 26 ms 208 KB Output is correct
9 Correct 27 ms 208 KB Output is correct
10 Correct 26 ms 324 KB Output is correct
11 Correct 28 ms 208 KB Output is correct
12 Correct 15 ms 208 KB Output is correct
13 Correct 28 ms 208 KB Output is correct
14 Correct 25 ms 304 KB Output is correct
15 Correct 25 ms 208 KB Output is correct
16 Correct 24 ms 300 KB Output is correct
17 Correct 24 ms 324 KB Output is correct
18 Correct 25 ms 208 KB Output is correct
19 Correct 24 ms 208 KB Output is correct
20 Correct 26 ms 208 KB Output is correct
# 결과 실행 시간 메모리 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
5 Correct 3 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 3 ms 320 KB Output is correct
10 Correct 4 ms 208 KB Output is correct
11 Correct 3 ms 208 KB Output is correct
12 Correct 3 ms 208 KB Output is correct
13 Correct 3 ms 208 KB Output is correct
14 Correct 3 ms 208 KB Output is correct
15 Correct 3 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 320 KB Output is correct
18 Correct 3 ms 208 KB Output is correct
19 Correct 3 ms 208 KB Output is correct
20 Correct 3 ms 208 KB Output is correct
21 Correct 3 ms 208 KB Output is correct
22 Correct 3 ms 208 KB Output is correct
23 Correct 3 ms 208 KB Output is correct
24 Correct 3 ms 208 KB Output is correct
25 Correct 3 ms 208 KB Output is correct
26 Correct 3 ms 208 KB Output is correct
27 Correct 3 ms 208 KB Output is correct
28 Correct 3 ms 208 KB Output is correct
29 Correct 3 ms 328 KB Output is correct
30 Correct 3 ms 208 KB Output is correct
31 Correct 3 ms 208 KB Output is correct
32 Correct 3 ms 208 KB Output is correct
33 Correct 3 ms 208 KB Output is correct
34 Correct 3 ms 208 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 3 ms 208 KB Output is correct
37 Correct 3 ms 208 KB Output is correct
38 Correct 3 ms 208 KB Output is correct
39 Correct 3 ms 208 KB Output is correct
40 Correct 3 ms 208 KB Output is correct