# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
412472 |
2021-05-27T00:34:18 Z |
rqi |
Naan (JOI19_naan) |
C++14 |
|
497 ms |
132564 KB |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef __int128 ll;
#define pb push_back
const int MOD = 1e9+7;
const int mx = 2005;
ll ABS(ll a){
if(a < 0) return -a;
return a;
}
ll GCD(ll a, ll b){
a = ABS(a); b = ABS(b);
if(a == 0) return b;
if(b == 0) return a;
return GCD(b%a, a);
}
struct frac{
ll n, d;
frac(){
n = 0;
d = 1;
}
frac(ll _n, ll _d){
if(_d < 0){
_n*=-1;
_d*=-1;
}
assert(_d >= 1);
ll g = GCD(_n, _d);
n = _n/g;
d = _d/g;
}
frac(ll _n){
n = _n;
d = 1;
}
};
frac operator+(frac a, frac b){
return frac(a.n*b.d+b.n*a.d, a.d*b.d);
}
frac& operator+=(frac& a, frac b){
a = a+b;
return a;
}
frac operator-(frac a, frac b){
b.n*=-1;
return a+b;
}
frac operator/(frac a, frac b){
return frac(a.n*b.d, a.d*b.n);
}
void print(frac a){
cout << (int)(a.n) << "/" << (int)(a.d) << " ";
}
bool isEqual(frac a, frac b){
return a.n*b.d == b.n*a.d;
}
bool isLess(frac a, frac b){
return a.n*b.d < b.n*a.d;
}
int N, L;
ll V[mx][mx];
frac poses[mx][mx]; //person i, j/N fraction
bool used[mx];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> N >> L;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= L; j++){
int val;
cin >> val;
V[i][j] = val;
}
}
for(int i = 1; i <= N; i++){
//cout << "i: " << i << "\n";
ll weight_sum = 0;
for(int j = 1; j <= L; j++){
weight_sum+=V[i][j];
}
int cur_eaten = 0; //current prefix eaten
frac cur_happy = frac(0);
for(int j = 1; j <= N; j++){
//cout << "j: " << j << "\n";
while(cur_eaten+1 <= L){
if(isLess(cur_happy+frac(V[i][cur_eaten+1], weight_sum), frac(j, N))){
cur_happy+=frac(V[i][cur_eaten+1], weight_sum);
cur_eaten++;
// cout << "cur_eaten: " << cur_eaten << "\n";
// print(cur_happy);
// cout << "\n";
}
else{
break;
}
}
assert(cur_eaten < L);
poses[i][j] = frac(cur_eaten)+(frac(j, N)-cur_happy)/(frac(V[i][cur_eaten+1], weight_sum));
}
}
// for(int i = 1; i <= N; i++){
// for(int j = 1; j <= N; j++){
// cout << i << " " << j << " ";
// print(poses[i][j]);
// cout << "\n";
// }
// }
vi perm;
for(int i = 1; i <= N; i++){
frac earliest = frac(MOD, 1);
for(int j = 1; j <= N; j++){
if(used[j]) continue;
if(isLess(poses[j][i], earliest)){
earliest = poses[j][i];
}
}
if(i <= N-1){
cout << int(earliest.n) << " " << int(earliest.d) << "\n";
}
for(int j = 1; j <= N; j++){
if(used[j]) continue;
if(isEqual(poses[j][i], earliest)){
perm.pb(j);
used[j] = 1;
break;
}
}
}
for(auto u: perm){
cout << u << " ";
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
126148 KB |
Output is correct |
2 |
Correct |
65 ms |
126208 KB |
Output is correct |
3 |
Correct |
56 ms |
126164 KB |
Output is correct |
4 |
Correct |
59 ms |
126148 KB |
Output is correct |
5 |
Correct |
55 ms |
126148 KB |
Output is correct |
6 |
Correct |
62 ms |
126132 KB |
Output is correct |
7 |
Correct |
57 ms |
126112 KB |
Output is correct |
8 |
Correct |
56 ms |
126148 KB |
Output is correct |
9 |
Correct |
56 ms |
126140 KB |
Output is correct |
10 |
Correct |
56 ms |
126132 KB |
Output is correct |
11 |
Correct |
56 ms |
126144 KB |
Output is correct |
12 |
Correct |
57 ms |
126192 KB |
Output is correct |
13 |
Correct |
56 ms |
126144 KB |
Output is correct |
14 |
Correct |
56 ms |
126304 KB |
Output is correct |
15 |
Correct |
56 ms |
126164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
126148 KB |
Output is correct |
2 |
Correct |
57 ms |
126172 KB |
Output is correct |
3 |
Correct |
57 ms |
126308 KB |
Output is correct |
4 |
Correct |
58 ms |
126340 KB |
Output is correct |
5 |
Correct |
57 ms |
126276 KB |
Output is correct |
6 |
Correct |
57 ms |
126236 KB |
Output is correct |
7 |
Correct |
56 ms |
126116 KB |
Output is correct |
8 |
Correct |
56 ms |
126208 KB |
Output is correct |
9 |
Correct |
57 ms |
126276 KB |
Output is correct |
10 |
Correct |
58 ms |
126288 KB |
Output is correct |
11 |
Correct |
58 ms |
126260 KB |
Output is correct |
12 |
Correct |
56 ms |
126164 KB |
Output is correct |
13 |
Correct |
57 ms |
126172 KB |
Output is correct |
14 |
Correct |
59 ms |
126328 KB |
Output is correct |
15 |
Correct |
57 ms |
126268 KB |
Output is correct |
16 |
Correct |
59 ms |
126352 KB |
Output is correct |
17 |
Correct |
59 ms |
126408 KB |
Output is correct |
18 |
Correct |
59 ms |
126288 KB |
Output is correct |
19 |
Correct |
58 ms |
126264 KB |
Output is correct |
20 |
Correct |
59 ms |
126280 KB |
Output is correct |
21 |
Correct |
58 ms |
126340 KB |
Output is correct |
22 |
Correct |
58 ms |
126352 KB |
Output is correct |
23 |
Correct |
55 ms |
126240 KB |
Output is correct |
24 |
Correct |
59 ms |
126236 KB |
Output is correct |
25 |
Correct |
57 ms |
126256 KB |
Output is correct |
26 |
Correct |
55 ms |
126264 KB |
Output is correct |
27 |
Correct |
59 ms |
126332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
126148 KB |
Output is correct |
2 |
Correct |
65 ms |
126208 KB |
Output is correct |
3 |
Correct |
56 ms |
126164 KB |
Output is correct |
4 |
Correct |
59 ms |
126148 KB |
Output is correct |
5 |
Correct |
55 ms |
126148 KB |
Output is correct |
6 |
Correct |
62 ms |
126132 KB |
Output is correct |
7 |
Correct |
57 ms |
126112 KB |
Output is correct |
8 |
Correct |
56 ms |
126148 KB |
Output is correct |
9 |
Correct |
56 ms |
126140 KB |
Output is correct |
10 |
Correct |
56 ms |
126132 KB |
Output is correct |
11 |
Correct |
56 ms |
126144 KB |
Output is correct |
12 |
Correct |
57 ms |
126192 KB |
Output is correct |
13 |
Correct |
56 ms |
126144 KB |
Output is correct |
14 |
Correct |
56 ms |
126304 KB |
Output is correct |
15 |
Correct |
56 ms |
126164 KB |
Output is correct |
16 |
Correct |
55 ms |
126148 KB |
Output is correct |
17 |
Correct |
57 ms |
126172 KB |
Output is correct |
18 |
Correct |
57 ms |
126308 KB |
Output is correct |
19 |
Correct |
58 ms |
126340 KB |
Output is correct |
20 |
Correct |
57 ms |
126276 KB |
Output is correct |
21 |
Correct |
57 ms |
126236 KB |
Output is correct |
22 |
Correct |
56 ms |
126116 KB |
Output is correct |
23 |
Correct |
56 ms |
126208 KB |
Output is correct |
24 |
Correct |
57 ms |
126276 KB |
Output is correct |
25 |
Correct |
58 ms |
126288 KB |
Output is correct |
26 |
Correct |
58 ms |
126260 KB |
Output is correct |
27 |
Correct |
56 ms |
126164 KB |
Output is correct |
28 |
Correct |
57 ms |
126172 KB |
Output is correct |
29 |
Correct |
59 ms |
126328 KB |
Output is correct |
30 |
Correct |
57 ms |
126268 KB |
Output is correct |
31 |
Correct |
59 ms |
126352 KB |
Output is correct |
32 |
Correct |
59 ms |
126408 KB |
Output is correct |
33 |
Correct |
59 ms |
126288 KB |
Output is correct |
34 |
Correct |
58 ms |
126264 KB |
Output is correct |
35 |
Correct |
59 ms |
126280 KB |
Output is correct |
36 |
Correct |
58 ms |
126340 KB |
Output is correct |
37 |
Correct |
58 ms |
126352 KB |
Output is correct |
38 |
Correct |
55 ms |
126240 KB |
Output is correct |
39 |
Correct |
59 ms |
126236 KB |
Output is correct |
40 |
Correct |
57 ms |
126256 KB |
Output is correct |
41 |
Correct |
55 ms |
126264 KB |
Output is correct |
42 |
Correct |
59 ms |
126332 KB |
Output is correct |
43 |
Incorrect |
497 ms |
132564 KB |
Integer parameter [name=A_i] equals to -1922096429, violates the range [1, 2000000000000] |
44 |
Halted |
0 ms |
0 KB |
- |