#include <vector>
std::vector<int> POSITIONS;
std::vector<int> DANCERS;
int NUM_OF_POSITIONS;
int OFFSET;
/**
* @brief
*
*/
void update_dancers_array() {
for (int i = 0; i < NUM_OF_POSITIONS; i++) {
DANCERS[POSITIONS[i]] = (OFFSET + i) % NUM_OF_POSITIONS;
}
OFFSET = 0;
}
/**
* @brief
*
*/
void update_positions_array() {
for (int i = 0; i < NUM_OF_POSITIONS; i++) {
POSITIONS[(DANCERS[i] + OFFSET) % NUM_OF_POSITIONS] = i;
}
OFFSET = 0;
}
/**
* @brief This procedure is called once at the beginning of the choreography.
*
* @param N The number of dancers.
* @param P Array of length N describing the initial order of the dancers.
*/
void init(int N, std::vector<int> P) {
NUM_OF_POSITIONS = N;
OFFSET = 0;
for (int i = 0; i < N; i++) {
POSITIONS.push_back(P[i]);
DANCERS.push_back(i);
}
update_dancers_array();
return;
}
void move_right(int K) {
OFFSET = (OFFSET + K) % NUM_OF_POSITIONS;
return;
}
void move_left(int K) {
OFFSET = (OFFSET - K + NUM_OF_POSITIONS) % NUM_OF_POSITIONS;
return;
}
/**
* @brief This procedure adds a move of type 3 to the sequence of moves.
*
*/
void swap_places() {
update_positions_array();
for (int i = 0; i < NUM_OF_POSITIONS / 2; i++) {
int temp = POSITIONS[2 * i];
POSITIONS[2 * i] = POSITIONS[2 * i + 1];
POSITIONS[2 * i + 1] = temp;
}
update_dancers_array();
return;
}
/**
* @brief This procedure adds a move of type 4 to the sequence of moves.
*
*/
void move_around() {
update_positions_array();
std::vector<int> temp = POSITIONS;
for (int i = 0; i < NUM_OF_POSITIONS; i++) {
POSITIONS[temp[i]] = i;
}
update_dancers_array();
return;
}
/**
* @brief This procedure should return the position of dancer D after performing every move added
* to the sequence of moves before this call.
*
* @param D an integer representing a dancer.
* @return int
*/
int get_position(int D) {
return (DANCERS[D] + OFFSET) % NUM_OF_POSITIONS;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
6200 KB |
Output is correct |
2 |
Correct |
64 ms |
6280 KB |
Output is correct |
3 |
Correct |
65 ms |
6200 KB |
Output is correct |
4 |
Correct |
64 ms |
6200 KB |
Output is correct |
5 |
Correct |
42 ms |
4436 KB |
Output is correct |
6 |
Correct |
42 ms |
4412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
500 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
796 KB |
Output is correct |
5 |
Correct |
4 ms |
456 KB |
Output is correct |
6 |
Correct |
5 ms |
1000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1002 ms |
4328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1002 ms |
4328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
6200 KB |
Output is correct |
2 |
Correct |
64 ms |
6280 KB |
Output is correct |
3 |
Correct |
65 ms |
6200 KB |
Output is correct |
4 |
Correct |
64 ms |
6200 KB |
Output is correct |
5 |
Correct |
42 ms |
4436 KB |
Output is correct |
6 |
Correct |
42 ms |
4412 KB |
Output is correct |
7 |
Execution timed out |
1002 ms |
4328 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
6200 KB |
Output is correct |
2 |
Correct |
64 ms |
6280 KB |
Output is correct |
3 |
Correct |
65 ms |
6200 KB |
Output is correct |
4 |
Correct |
64 ms |
6200 KB |
Output is correct |
5 |
Correct |
42 ms |
4436 KB |
Output is correct |
6 |
Correct |
42 ms |
4412 KB |
Output is correct |
7 |
Correct |
3 ms |
500 KB |
Output is correct |
8 |
Correct |
4 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
796 KB |
Output is correct |
11 |
Correct |
4 ms |
456 KB |
Output is correct |
12 |
Correct |
5 ms |
1000 KB |
Output is correct |
13 |
Execution timed out |
1002 ms |
4328 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |