Submission #566932

# Submission time Handle Problem Language Result Execution time Memory
566932 2022-05-23T06:31:06 Z 600Mihnea Naan (JOI19_naan) C++17
100 / 100
413 ms 100836 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

struct Fraction {
  ll a;
  ll b;

  Fraction(ll a, ll b) : a(a), b(b) {

  }
};

ld getld(Fraction fr) {
  return (ld)fr.a/(ld)fr.b;
}

bool operator < (Fraction First,Fraction Second) {
  return (ld)First.a/First.b<(ld)Second.a/Second.b;  /// may be a bug here
}

Fraction operator + (Fraction First,ll Second) {
  return Fraction(First.a+Second*First.b, First.b);
}

Fraction operator + (ll Second, Fraction First) {
  return Fraction(First.a+Second*First.b, First.b);
}


Fraction operator - (Fraction First,ll Second) {
  return Fraction(First.a-Second*First.b, First.b);
}

Fraction operator - (ll Second,Fraction First) {
  return Fraction(-First.a+Second*First.b, First.b);
}

Fraction operator * (Fraction First,ll Second) {
  return Fraction(First.a*Second, First.b);
}

Fraction operator * (ll Second, Fraction First) {
  return Fraction(First.a*Second, First.b);
}


signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  int People,n;
  cin>>People>>n;
  vector<vector<int>> a(People,vector<int> (n));
  vector<vector<Fraction>> splitPoint(People,vector<Fraction>(People,Fraction(0,1)));

  for (int i=0;i<People;i++) {
    for (int j=0;j<n;j++) {
      cin>>a[i][j];
    }
  }

  for (int Person=0;Person<People;Person++) {
    ///cout<<"Person = "<<Person<<"\n";
    vector<int> elements=a[Person];
    ll totalSum=0;
    for (auto &x:elements) {
      totalSum+=x;
    }
    int done=0;
    ll currentSum=0;
    Fraction din(0, 1);
    for (int j=0;j<People;j++) {
      /// compute splitPoint[Person][j]
      /// the first having <= (j + 1) * totalSum / People
    ///  cout<<j<<" = "<<j<<", din = "<<getld(din)<<" "<<(ld)j/7<<"\n";
      Fraction want((j+1)*totalSum, People);
     /// cout<<"want = "<<getld(want)<<"\n\n";
      assert(done<n);
      while (Fraction(currentSum+elements[done],1)<want){
        assert(done<n);
        Fraction FF=Fraction(currentSum+elements[done], 1), SS=want;
       /// cout<<"\t\t\t\t"<<fixed<<setprecision(6)<<getld(FF)<<" "<<getld(SS)<<"\n";
       /// cout<<fixed<<setprecision(6)<<(ld)FF.a/(ld)FF.b<<" vs "<<(ld)SS.a/(ld)SS.b<<"\n";
        currentSum+=elements[done++];
        din=Fraction(0,1);
        assert(done<n);
      }
      assert(done<n);
    ///  cout<<j<<" : "<<done<<"\n";
      /// currentSum + elements[done] * x = want
      Fraction dif=want-currentSum;
      /// elements[done] * x = dif
      Fraction x(dif.a,dif.b*elements[done]);
      splitPoint[Person][j]=done+x;

     /// cout<<"lol : "<<fixed<<setprecision(6)<<getld(splitPoint[Person][j])<<"\n";
      din=x;

      /// x = x - din
      continue;
      //while (Fraction(currentSum+elements[done])<Fraction((j+1)*totalSum,People)) {
      //  assert(done<n);
     //   currentSum+=elements[done++];
      //}
      assert(done<n);
      /// currentSum + elements[done] * x = (j + 1) * totalSum / People
      /// elements[done] * x = ((j + 1) * totalSum - currentSum * People) / People
      /// x = ((j + 1) * totalSum - currentSum * People) / (elements[done] * People)
    ///  Fraction x((j + 1) * totalSum - currentSum * People, elements[done] * People);
    }
    if (0) {
      assert(Person==0);
      cout<<"good \n";
      exit(0);
    }
  }

  vector<bool> valid(People,1);

  vector<int> guys;

  for (int ch=0;ch<People;ch++) {
    int sol=-1;
    for (int i=0;i<People;i++){
      if (valid[i]) {
        if (sol==-1) {
          sol=i;
        }else{
          if (splitPoint[i][ch]<splitPoint[sol][ch]) {
            sol=i;
          }
        }
      }
    }
    assert(sol!=-1);
    valid[sol]=0;
    if (ch!=People-1) {
      cout<<splitPoint[sol][ch].a<<" "<<splitPoint[sol][ch].b<<"\n";
    }
    guys.push_back(sol);
  }
  cout<<"\n";
  for (auto &Guy:guys) {
    cout<<Guy+1<<" ";
  }
  cout<<"\n";

  return 0;
  for (auto &v:splitPoint) {
    for (auto &fr:v) {
      cout<<fr.a<<"/"<<fr.b<<" ";
    }
    cout<<"\n";
  }

}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:84:18: warning: variable 'FF' set but not used [-Wunused-but-set-variable]
   84 |         Fraction FF=Fraction(currentSum+elements[done], 1), SS=want;
      |                  ^~
naan.cpp:84:61: warning: variable 'SS' set but not used [-Wunused-but-set-variable]
   84 |         Fraction FF=Fraction(currentSum+elements[done], 1), SS=want;
      |                                                             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 380 KB Output is correct
43 Correct 35 ms 7880 KB Output is correct
44 Correct 183 ms 46212 KB Output is correct
45 Correct 113 ms 20300 KB Output is correct
46 Correct 17 ms 2388 KB Output is correct
47 Correct 140 ms 29144 KB Output is correct
48 Correct 106 ms 60584 KB Output is correct
49 Correct 41 ms 15184 KB Output is correct
50 Correct 201 ms 76748 KB Output is correct
51 Correct 110 ms 27840 KB Output is correct
52 Correct 222 ms 66140 KB Output is correct
53 Correct 167 ms 58576 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 50 ms 32156 KB Output is correct
56 Correct 142 ms 39500 KB Output is correct
57 Correct 120 ms 33100 KB Output is correct
58 Correct 150 ms 57316 KB Output is correct
59 Correct 138 ms 32416 KB Output is correct
60 Correct 398 ms 100716 KB Output is correct
61 Correct 397 ms 100696 KB Output is correct
62 Correct 413 ms 100192 KB Output is correct
63 Correct 389 ms 100836 KB Output is correct
64 Correct 384 ms 100684 KB Output is correct
65 Correct 289 ms 87380 KB Output is correct
66 Correct 284 ms 87504 KB Output is correct
67 Correct 287 ms 87372 KB Output is correct
68 Correct 148 ms 42828 KB Output is correct
69 Correct 169 ms 40644 KB Output is correct
70 Correct 162 ms 52604 KB Output is correct
71 Correct 239 ms 63136 KB Output is correct