이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x),end(x)
#define both(x) x.first,x.second
signed main()
{
int N,R,rank;
cin >> N >> R >> rank;
vector<int> ranks(2*N-1);
for(auto &&i : ranks) cin >> i;
// will eventually have the top half (excluding the best) cycle around, and the worst half (excluding middle)
// be stationary
// lower numbers move
// if rank == 1: any works, return N
if(rank == 1) {cout << N << "\n"; exit(0);}
// just simulate all the positions
int minend = INT_MAX;
int position = -1;
for(int pos = 2*N-2; pos >= 0; pos-=2)
{
vector<pair<int,int>> people;
for(int i = 0; i < 2*N-1;)
{
if(i==pos) people.push_back({ranks[i++],rank});
else people.push_back({ranks[i++],ranks[i++]});
}
for(int i = 0; i < R; i++)
{
if(i > 3*N && i < R-N)
{
i += ((R-i)/N)*N;
}
vector<pair<int,int>> people2(people.size());
people2.back() = {max(both(people[0])),max(both(people.back()))};
people2[0] = {min(both(people[0])),min(both(people[1]))};
for(int i = 1; i < people.size()-1; i++)
{
people2[i] = {max(both(people[i])),min(both(people[i+1]))};
}
people = people2;
}
int r = 0;
for(; people[r].first!=rank && people[r].second != rank;r++);
if(r < minend)
{
minend = r;
position = pos/2+1;
}
}
cout << position << "\n";
// no.2 always moves to pos1, until 1 arrives, then cycles
// unless it starts with 1, then it waits once first
// no.3 always moves to pos1, until 2 or 1 arrives, then cycles
// waits with starting until neither 1 nor 2 is at its position
// can be complicated if (2 1) (3 ...)
// as 1 moves up, and 3 comes to 2: (2 3) (...)
// next, 2 moves up
}
컴파일 시 표준 에러 (stderr) 메시지
archery.cpp: In function 'int main()':
archery.cpp:28:54: warning: operation on 'i' may be undefined [-Wsequence-point]
28 | else people.push_back({ranks[i++],ranks[i++]});
| ~^~
archery.cpp:39:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 1; i < people.size()-1; i++)
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |