Submission #1000165

#TimeUsernameProblemLanguageResultExecution timeMemory
1000165flappybirdNaan (JOI19_naan)C++17
100 / 100
567 ms86356 KiB
#include <bits/stdc++.h> #include <cassert> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 2020 #define MAXQ 101010 #define INF 1000000000000000000 #define MOD 998244353 #define bb ' ' #define ln '\n' #define Ln '\n' ll V[MAX][MAX]; ll sum[MAX][MAX]; int N, L; bool operator>(pll p1, pll p2) { return (__int128)p1.first * p2.second > (__int128)p2.first * p1.second; } bool operator<=(pll p1, ll p2) { return (__int128)p1.first <= (__int128)p2 * p1.second; } pll get(int ind, int v) { int l, r; l = 0; r = L; while (r - l > 1) { int m = l + r >> 1; if (pll(v * sum[ind][L], N) <= sum[ind][m]) r = m; else l = m; } r--; return pll(V[ind][r + 1] * N * r + sum[ind][L] * v - sum[ind][r] * N, V[ind][r + 1] * N); } pll ans[MAX]; int P[MAX]; int vis[MAX]; signed main() { ios::sync_with_stdio(false), cin.tie(0); cin >> N >> L; int i, j; for (i = 1; i <= N; i++) for (j = 1; j <= L; j++) cin >> V[i][j], sum[i][j] = sum[i][j - 1] + V[i][j]; for (i = 1; i <= N; i++) { pll mn = pll(L + 1, 1); int mv = 0; for (j = 1; j <= N; j++) { if (vis[j]) continue; pll v = get(j, i); if (mn > v) mn = v, mv = j; } P[i] = mv; vis[mv] = 1; ans[i] = mn; ll g = gcd(ans[i].first, ans[i].second); ans[i].first /= g; ans[i].second /= g; if (i < N) cout << ans[i].first << bb << ans[i].second << ln; } for (i = 1; i <= N; i++) cout << P[i] << bb; }

Compilation message (stderr)

naan.cpp: In function 'pll get(int, int)':
naan.cpp:28:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |   int m = l + r >> 1;
      |           ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...