Submission #722863

# Submission time Handle Problem Language Result Execution time Memory
722863 2023-04-13T03:06:55 Z jamezzz Olympiads (BOI19_olympiads) C++17
44 / 100
129 ms 2112 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#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];
ll q,memo[maxn][64][6];
vector<int> d[6];
set<il> s;

ll dp(int i,int msk,int rem){
	if(i==n)return (rem==0)&&(msk==(1<<k)-1);
	if(memo[i][msk][rem]!=-1)return memo[i][msk][rem];
	ll ans=dp(i+1,msk,rem);
	if(rem){
		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);
	}
	return memo[i][msk][rem]=ans;
}

main(){
	sf("%lld%lld%lld",&n,&k,&q);
	for(int i=0;i<n;++i){
		for(int j=0;j<k;++j){
			sf("%lld",&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 ",c[j]);
		//pf("\n");
		memset(memo,-1,sizeof memo);
		q-=dp(0,0,k);
		//pf("q: %d\n",q);
		//pf("dp: %lld\n",dp(0,0,k));
		if(q<=0){
			pf("%lld\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

olympiads.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main(){
      | ^~~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:89:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |  sf("%lld%lld%lld",&n,&k,&q);
      |    ^
olympiads.cpp:92:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |    sf("%lld",&a[i][j]);
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1876 KB Output is correct
2 Correct 34 ms 1876 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1840 KB Output is correct
2 Correct 65 ms 2016 KB Output is correct
3 Correct 99 ms 2112 KB Output is correct
4 Correct 129 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Incorrect 29 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1876 KB Output is correct
2 Correct 34 ms 1876 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 30 ms 1840 KB Output is correct
6 Correct 65 ms 2016 KB Output is correct
7 Correct 99 ms 2112 KB Output is correct
8 Correct 129 ms 2056 KB Output is correct
9 Correct 5 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Incorrect 29 ms 1876 KB Output isn't correct
12 Halted 0 ms 0 KB -