Submission #722875

#TimeUsernameProblemLanguageResultExecution timeMemory
722875jamezzzOlympiads (BOI19_olympiads)C++17
100 / 100
1288 ms1820 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define dbg(...) printf(__VA_ARGS__); #define getchar_unlocked getchar #else #define dbg(...) #endif #define sf scanf #define pf printf #define fi first #define se second #define pb push_back #define psf push_front #define ppb pop_back #define ppf pop_front #define sz(x) (int)x.size() #define mnto(x,y) x=min(x,(__typeof__(x))y) #define mxto(x,y) x=max(x,(__typeof__(x))y) #define INF 1023456789 #define LINF 1023456789123456789 #define all(x) x.begin(),x.end() #define lb(x,v) (lower_bound(all(x),v)-x.begin()) #define ub(x,v) (upper_bound(all(x),v)-x.begin()) #define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin()); typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef pair<ll,ll> pll; typedef pair<int,ll> il; typedef tuple<int,int,int> iii; typedef tuple<int,int,int,int> iiii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; mt19937 rng(time(0)); #define mod 1000000007 inline int add(int a,int b){ int r=a+b; while(r>=mod)r-=mod; while(r<0)r+=mod; return r; } inline int mult(int a,int b){ return (int)(((ll)(a*b))%mod); } inline int rd(){ int x=0; char ch=getchar_unlocked(); while(!(ch&16))ch=getchar();//keep reading while current character is whitespace while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered x=(x<<3)+(x<<1)+(ch&15); ch=getchar_unlocked(); } return x; } #define maxn 505 int n,k,a[maxn][6],b[maxn][6],c[6],q,memo[maxn][64][6]; vector<int> d[6]; set<il> s; int dp(int i,int msk,int rem){ if(rem==0&&msk!=(1<<k)-1)return 0; if(i==n)return (rem==0)&&(msk==(1<<k)-1); if(memo[i][msk][rem]!=-1)return memo[i][msk][rem]; int ans=dp(i+1,msk,rem); if(rem>0){ int nmsk=msk; bool pos=true; for(int j=0;j<k;++j){ if(b[i][j]==c[j])nmsk|=(1<<j); else if(b[i][j]>c[j])pos=false; } if(pos){ ans+=dp(i+1,nmsk,rem-1); ans=min(ans,q); } } //if(dbg&&ans)pf("%d %d %d: %d\n",i,msk,rem,ans); return memo[i][msk][rem]=ans; } int main(){ sf("%d%d%d",&n,&k,&q); for(int i=0;i<n;++i){ for(int j=0;j<k;++j){ sf("%d",&a[i][j]); d[j].pb(a[i][j]); } } int tot=0;ll cur=0; for(int j=0;j<k;++j){ disc(d[j]); cur*=500; cur+=sz(d[j])-1; tot+=d[j].back(); } s.insert({tot,cur}); for(int i=0;i<n;++i){ for(int j=0;j<k;++j){ b[i][j]=lb(d[j],a[i][j]); } } while(!s.empty()){ auto[sm,cur]=*--s.end(); s.erase(--s.end()); ll tcur=cur; for(int j=k-1;j>=0;--j){ c[j]=(int)(tcur%500); tcur/=500; } //pf("cur %d: ",sm); //for(int j=0;j<k;++j)pf("%d ",d[j][c[j]]); //pf("\n"); memset(memo,-1,sizeof memo); //if(d[0][c[0]]==5)dbg=true; q-=dp(0,0,k); //dbg=false; //pf("q: %d\n",q); //pf("dp: %d\n",dp(0,0,k)); if(q<=0){ pf("%d\n",sm); return 0; } ll mult=1; for(int j=k-1;j>=0;--j){ if(c[j]!=0)s.insert({sm-d[j][c[j]]+d[j][c[j]-1],cur-mult}); mult*=500; } } assert(false); } /* 5 4 4 7 0 4 9 3 0 8 4 1 1 3 7 5 1 3 4 4 2 2 9 */

Compilation message (stderr)

olympiads.cpp: In function 'int main()':
olympiads.cpp:91:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |  sf("%d%d%d",&n,&k,&q);
      |    ^
olympiads.cpp:94:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |    sf("%d",&a[i][j]);
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...