File size: 1,359 Bytes
5fed0fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "testlib.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

set<int>s[5];

int main(int argc, char *argv[]) {
  /*
   * inf: input
   * ouf: player output
   * ans: standard output
   */
  registerTestlibCmd(argc, argv);

  int n = inf.readInt();
  for(int i = 1; i <= n; i++){
    s[1].insert(i);
  }
  int m = ouf.readInt();
  for(int i = 1; i <= m; i++){
    int a = ouf.readInt(1, 3), b = ouf.readInt(1, 3);
    if(a == b)quitf(_wa, "Same basket");
    if(s[a].empty())quitf(_wa, "Empty basket a");
    int mida = (s[a].size()+2)/2;
    set<int>::iterator it;
    for(it = s[a].begin(); it != s[a].end(); it++){
      mida--;
      if(mida == 0)break;
    }
    int val = (*it);
    s[a].erase(val);
    s[b].insert(val);
    int midb = (s[b].size()+2)/2;
    for(it = s[b].begin(); it != s[b].end(); it++){
      midb--;
      if(midb == 0)break;
    }
    if((*it) != val)quitf(_wa, "Invalid target basket b on %d operation", i);
  } 
  if(s[3].size()==n){
    int ref = ans.readInt();
    double score = (2.0*ref-1.0*m)/(1.0*ref);
    if (score < 0) score = 0.0;
    double unbounded_score = max(0.0, score);
    score = min(score, 1.0);
    score = max(score, 0.0);
    quitp(score, "Ratio: %.3lf, RatioUnbounded: %.3lf", score, unbounded_score);
  } 
  else quitf(_wa, "Invalid operation");
}