Submission #384370

#TimeUsernameProblemLanguageResultExecution timeMemory
384370i_am_noobNaan (JOI19_naan)C++17
100 / 100
193 ms117612 KiB
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma") #include<bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") using namespace std; #define ll long long #define int ll #define ull unsigned long long #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back //#define inf 1010000000 #define inf 4000000000000000000 #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr << x << endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 826 #endif inline char readchar(){ const int maxn=1000000; static char buf[maxn],*p=buf,*q=buf; if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF; else return *p++; } inline int readint(){ int c=readchar(),x=0,neg=0; while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar(); if(c=='-') neg=1,c=readchar(); while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar(); return neg?-x:x; } const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; const int maxn=2005; //i_am_noob int n,m,a[maxn][maxn],ans[maxn]; bool vis[maxn]; struct rational{ int x,y; bool operator <(const rational& o) const {return x/y!=o.x/o.y?x/y<o.x/o.y:(x%y)*o.y<y*(o.x%o.y);} }; rational val[maxn][maxn]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); #ifdef i_am_noob freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); freopen("output2.txt","w",stderr); #endif n=readint(),m=readint(); rep(n) rep1(j,m) a[i][j]=readint(); rep(n){ int sum=0; rep1(j,m) sum+=a[i][j]; int cur=0,curval=0; rep1(j,n-1){ while((curval+a[i][cur])*n<=sum*(j+1)){ curval+=a[i][cur]; cur++; } val[i][j].x=cur*n*a[i][cur]+sum*(j+1)-curval*n; val[i][j].y=n*a[i][cur]; } } rep(n-1){ rational minn={inf,1}; int minid; rep1(j,n) if(!vis[j]) if(val[j][i]<minn) minn=val[j][i],minid=j; vis[minid]=1; ans[i]=minid; cout << minn.x << ' ' << minn.y << "\n"; } rep(n) if(!vis[i]) ans[n-1]=i; rep(n) cout << ans[i]+1 << " \n"[i==n-1]; return 0; }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:86:15: warning: 'minid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |         ans[i]=minid;
      |         ~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...