Submission #722865

# Submission time Handle Problem Language Result Execution time Memory
722865 2023-04-13T03:17:28 Z jamezzz Olympiads (BOI19_olympiads) C++17
44 / 100
146 ms 2104 KB
#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];
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;
}

int main(){
	sf("%d%d%lld",&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;
		int chk=0;
		for(int j=k-1;j>=0;--j){
			c[j]=(int)(tcur%500);
			tcur/=500;
			chk+=d[j][c[j]];
		}
		assert(chk==sm);
		//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("%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

olympiads.cpp: In function 'int main()':
olympiads.cpp:87:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |  sf("%d%d%lld",&n,&k,&q);
      |    ^
olympiads.cpp:90:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |    sf("%d",&a[i][j]);
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1876 KB Output is correct
2 Correct 41 ms 1892 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 32 ms 1864 KB Output is correct
2 Correct 63 ms 2044 KB Output is correct
3 Correct 103 ms 2104 KB Output is correct
4 Correct 146 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Incorrect 32 ms 1876 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1876 KB Output is correct
2 Correct 41 ms 1892 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 32 ms 1864 KB Output is correct
6 Correct 63 ms 2044 KB Output is correct
7 Correct 103 ms 2104 KB Output is correct
8 Correct 146 ms 2088 KB Output is correct
9 Correct 5 ms 1876 KB Output is correct
10 Correct 2 ms 1876 KB Output is correct
11 Incorrect 32 ms 1876 KB Output isn't correct
12 Halted 0 ms 0 KB -