Submission #722857

# Submission time Handle Problem Language Result Execution time Memory
722857 2023-04-13T02:54:43 Z jamezzz Olympiads (BOI19_olympiads) C++17
0 / 100
161 ms 3540 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;
		for(int j=k-1;j>=0;--j){
			c[j]=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);
		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 52 ms 1876 KB Output is correct
2 Correct 53 ms 1884 KB Output is correct
3 Correct 3 ms 1876 KB Output is correct
4 Runtime error 3 ms 3540 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1868 KB Output is correct
2 Correct 70 ms 2000 KB Output is correct
3 Correct 99 ms 2168 KB Output is correct
4 Incorrect 161 ms 2284 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1876 KB Output is correct
2 Correct 53 ms 1884 KB Output is correct
3 Correct 3 ms 1876 KB Output is correct
4 Runtime error 3 ms 3540 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -