#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAX_B = 1e6;
const int MAX_N = 2000;
const int MAX_L = 2000;
bool active[MAX_N];
int permutation[MAX_N];
double happiness[MAX_N][MAX_L + 1], sumHappiness[MAX_N][MAX_L + 1];
double happy[MAX_N], timeFrac[MAX_N], timeFractions[MAX_N];
int main() {
int n, l;
cin >> n >> l;
for ( int i = 0; i < n; i++ ) {
happy[i] = 0;
sumHappiness[i][0] = 0;
for ( int j = 1; j <= l; j++ ) {
int aux;
cin >> aux;
happiness[i][j] = aux;
happy[i] += aux;
sumHappiness[i][j] = sumHappiness[i][j - 1] + happiness[i][j];
}
happy[i] /= n;
}
for ( int i = 0; i < n; i++ )
active[i] = true;
timeFractions[0] = 0;
permutation[0] = 0;
for ( int pas = 1; pas <= n; pas++ ) {
for ( int i = 0; i < n; i++ ) {
if ( !active[i] ) {
timeFrac[i] = INF + 1;
continue;
}
int j = floor( timeFractions[pas - 1] );
double crtHappiness = happiness[i][j + 1] * (j + 1 - timeFractions[pas - 1]);
if ( crtHappiness > happy[i] ) {
timeFrac[i] = timeFractions[pas - 1] + happy[i] / happiness[i][j + 1];
continue;
}
int left = j + 1, right = l + 1;
while ( right - left > 1 ) {
int mid = (left + right) / 2;
if ( crtHappiness + (sumHappiness[i][mid] - sumHappiness[i][j + 1]) < happy[i] )
left = mid;
else
right = mid;
}
if ( left == l ) {
timeFrac[i] = INF;
continue;
}
crtHappiness = crtHappiness + (sumHappiness[i][left] - sumHappiness[i][j + 1]);
timeFrac[i] = left + (happy[i] - crtHappiness) / happiness[i][left + 1];
}
int p = 0;
for ( int i = 0; i < n; i++ ) {
if ( active[i] && timeFrac[i] < timeFrac[p] )
p = i;
}
timeFractions[pas] = timeFrac[p];
permutation[pas] = p;
active[p] = false;
}
for ( int i = 1; i < n; i++ )
cout << (int)floor( timeFractions[i] * MAX_B ) + 1 << " " << MAX_B << "\n";
for ( int i = 1; i <= n; i++ )
cout << permutation[i] + 1 << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
64 ms |
36176 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |