답안 #147841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147841 2019-08-31T00:04:52 Z Lovely Trick(#3691, xdoju) 백점을 받아랏! (FXCUP4_hundred) C++17
100 / 100
9 ms 384 KB
#include "hundred.h"
using namespace std;

int diff[102];

string GetHundredPoints(int A, int B, int C) {
  string now = string(A, 'A') + string(B, 'B') + string(C, 'C');
  int original = Mark(now);

  int neq = -1;
  for(int i = 1; i < 100; i++){
    if(now[i] != now[0]){ neq = i; break; }
  }

  if(neq == -1) return now;

  for(int i = neq; i < 100; i++){
    swap(now[0], now[i]);
    int v = Mark(now);
    swap(now[0], now[i]);

    int d = v - original;

    if(d == -2 || d == 1){
      diff[i] = now[i] - now[0];
    }

    if(d == -1 || d == 2){
      diff[i] = now[0] - now[i];
    }
  }

  for(int i = 1; i < neq; i++){
    swap(now[i], now[neq]);
    int v = Mark(now);
    swap(now[i], now[neq]);

    int d = v - original;

    if(d == -2 || d == 1){
      diff[i] = diff[neq] + now[i] - now[neq];
    }

    if(d == -1 || d == 2){
      diff[i] = diff[neq] + now[neq] - now[i];
    }

    if(d == 0){
      diff[i] = diff[neq];
    }
  }

  int c0 = 0, c1 = 0, c2 = 0;

  for(int i = 0; i < 100; i++){
    int &d = diff[i];
    while(d < 0) d += 3;
    while(d > 2) d -= 3;

    (d == 0 ? c0 : d == 1 ? c1 : c2)++;
  }

  string ans = string();

  if(c0 == A && c1 == B && c2 == C){
    for(int i = 0; i < 100; i++) ans += (diff[i] == 0 ? 'A' : diff[i] == 1 ? 'B' : 'C');
  }
  if(c0 == B && c1 == C && c2 == A){
    for(int i = 0; i < 100; i++) ans += (diff[i] == 0 ? 'B' : diff[i] == 1 ? 'C' : 'A');
  }
  if(c0 == C && c1 == A && c2 == B){
    for(int i = 0; i < 100; i++) ans += (diff[i] == 0 ? 'C' : diff[i] == 1 ? 'A' : 'B');
  }

  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 9 ms 256 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 256 KB Output is correct
3 Correct 9 ms 256 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
6 Correct 7 ms 256 KB Output is correct
7 Correct 7 ms 256 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 6 ms 256 KB Output is correct
13 Correct 8 ms 256 KB Output is correct
14 Correct 8 ms 384 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct