Submission #1094284

#TimeUsernameProblemLanguageResultExecution timeMemory
1094284akim9905Naan (JOI19_naan)C++17
0 / 100
2 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout) #define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(x) (x).begin(), (x).end() #define allr(x) x.rbegin(), x.rend() #define cmprs(x) sort(all(x)),x.erase(unique(all(x)),x.end()) #define endl "\n" #define sp " " #define pb push_back #define lb lower_bound #define ub upper_bound #define F first #define S second #define rz resize #define sz(a) (int)(a.size()) #define clr(a) a.clear() typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, ll> pil; typedef tuple<int, int, int> tpi; typedef tuple<ll, ll, ll> tpl; typedef pair<double, ll> pdl; typedef pair<double, int> pdi; const int dx[] = {1,-1,0,0,1,1,-1,-1}; const int dy[] = {0,0,1,-1,1,-1,1,-1}; const ll MOD = 1e9+7; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 2020; // PLZ CHK! #define double long double int N,L,V[MAX][MAX],P[MAX][MAX]; int chk[MAX]; double avg[MAX]; int main() { fio(); cin>>N>>L; for (int i=1; i<=N; i++) { for (int j=1; j<=L; j++) { cin>>V[i][j]; P[i][j]=P[i][j-1]+V[i][j]; avg[i]+=V[i][j]; } avg[i]/=1.0*N; } const double eps=1e-12; vector<int> per; double cur=0.0; vector<pair<double,int>> ans; for (int d=1; d<=N && cur+eps<L; d++) { vector<pair<double,int>> nxts; int curc=(int)ceil(cur); for (int i=1; i<=N; i++) { if (chk[i]) continue; double le=cur,ri=L,nxt=L; for (int t=0; t<100; t++) { double md=(le+ri)/2.0; double cal=0.0; int mdf=(int)floor(md),mdc=(int)ceil(md); cal+=1.0*(curc-cur)*V[i][curc]; cal+=1.0*P[i][mdf]-1.0*P[i][curc]; cal+=1.0*(md-mdf)*V[i][mdc]; if (avg[i]<cal || abs(avg[i]-cal)<eps) { ri=md; nxt=md; } else le=md; } double res=0.0; int ntf=(int)floor(nxt),ntc=(int)ceil(nxt); res+=1.0*(curc-cur)*V[i][curc]; res+=1.0*P[i][ntf]-1.0*P[i][curc]; res+=1.0*(nxt-ntf)*V[i][ntc]; if (avg[i]<res || abs(res-avg[i])<eps) { if (d==N) nxt=L; nxts.pb({nxt,i}); } } if (nxts.empty()) { cout<<-1; return 0; } sort(all(nxts)); ans.pb({nxts[0].F-cur,nxts[0].S}); cur=nxts[0].F; chk[nxts[0].S]=1; } double seg=0.0; for (int i=0; i<N-1; i++) { auto [a,b]=ans[i]; seg+=a; ll p=seg*1e9, q=1e9; cout<<p<<sp<<q<<endl; } for (auto [a,b]:ans) cout<<b<<sp; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...