# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1094301 | 2024-09-29T10:03:24 Z | akim9905 | Naan (JOI19_naan) | C++17 | 2 ms | 604 KB |
#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! struct frac { ll p,q; bool operator < (frac t) const { return p*t.q<t.p*q; } bool operator <= (frac t) const { return p*t.q<=t.p*q; } bool operator == (frac t) const { return p*t.q==t.p*q; } frac operator + (frac t) const { frac ret={p*t.q+t.p*q,q*t.q}; ll g=gcd(ret.p, ret.q); ret.p/=g, ret.q/=g; return ret; } frac operator - (frac t) const { frac ret={p*t.q-t.p*q,q*t.q}; ll g=gcd(abs(ret.p), abs(ret.q)); ret.p/=g, ret.q/=g; return ret; } frac operator * (frac t) const { frac ret={p*t.p, q*t.q}; ll g=gcd(abs(ret.p), abs(ret.q)); ret.p/=g, ret.q/=g; return ret; } ll ceil(frac t) { return (t.p+t.q-1)/t.p; } ll floor(frac t) { return t.p/t.q; } }; int N,L; ll V[MAX][MAX],P[MAX][MAX]; frac avg[MAX]; int chk[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]; } ll g=gcd(P[i][L],N); avg[i]={P[i][L]/g,N/g}; } frac cur={0,1}; vector<pair<frac,int>> ans; for (int d=1; d<=N; d++) { vector<pair<frac,int>> nxts; auto [p,q]=cur; ll crc=cur.ceil(cur); frac curc={crc,1}; for (int i=1; i<=N; i++) { if (chk[i]) continue; frac le=cur,ri={L,1},nxt={L,1}; for (int t=0; t<50; t++) { frac md=(le+ri)*frac{1,2}; frac cal={0,1}; int mdf=md.floor(md), mdc=md.ceil(md); cal=cal+(curc-cur)*frac{V[i][crc],1}; cal=cal+frac{P[i][mdf]-P[i][crc],1}; cal=cal+(md-frac{mdf,1})*frac{V[i][mdc],1}; if (avg[i]<=cal) { ri=md; nxt=md; } else le=md; } if (d==N) nxt={L,1}; frac res={0,1}; int ntf=nxt.floor(nxt), ntc=nxt.ceil(nxt); res=res+(curc-cur)*frac{V[i][crc],1}; res=res+frac{P[i][ntf]-P[i][crc],1}; res=res+(nxt-frac{ntf,1})*frac{V[i][ntc],1}; if (avg[i]<=res) { 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; } frac seg={0,1}; for (int i=0; i<N-1; i++) { auto [a,b]=ans[i]; seg=seg+a; cout<<seg.p<<sp<<seg.q<<endl; } for (int i=0; i<N; i++) { auto [a,b]=ans[i]; cout<<b<<sp; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 604 KB | Execution killed with signal 4 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 604 KB | Execution killed with signal 4 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 604 KB | Execution killed with signal 4 |
2 | Halted | 0 ms | 0 KB | - |