답안 #482661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482661 2021-10-26T02:43:23 Z robell Ice Hockey World Championship (CEOI15_bobek) C++14
80 / 100
1000 ms 117088 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define int long long
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define f first
#define s second
int mod=1e9+7;
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
ll N, M, c[40];
ll s1[(1<<20)], s2[(1<<20)];
vector<int> v1, v2;
unordered_map<ll,int> m;
set<ll> store;
vector<ll> vals;
vector<ll> counts={0};
void setup1(){
	for (int i=1;i<(1<<v1.size());i++){
		for (int j=0;j<v1.size();j++){
			if (i&(1<<j)){
				int n = i&(~(1<<j));
				s1[i]=s1[n]+v1[j];
				break;
			}
		}
	}
}
void setup2(){
	for (int i=1;i<(1<<v2.size());i++){
		for (int j=0;j<v2.size();j++){
			if (i&(1<<j)){
				int n = i&(~(1<<j));
				s2[i]=s2[n]+v2[j];
				break;
			}
		}
	}
}
int32_t main(){
	setIO(); cin >> N >> M; s1[0]=0;s2[0]=0;
	for (int i=0;i<N;i++){cin >> c[i];}
	for (int i=0;i<N/2;i++) v1.pb(c[i]);
	for (int i=N/2;i<N;i++) v2.pb(c[i]);
	setup1();setup2();
	for (int i=0;i<(1<<v1.size());i++){
		m[s1[i]]++;
		store.insert(s1[i]);
	}
	for (ll j:store) vals.pb(j);
	for (ll j:store) counts.pb(counts.back()+m[j]);
	ll res = 0;
	for (int i=0;i<(1<<v2.size());i++){
		ll diff = M-s2[i];
		int l=0,r=vals.size()-1;
		while (l!=r){
			int mid = (l+r+1)/2;
			if (vals[mid]<=diff) l=mid;
			else r=mid-1;
		}
		if (vals[r]<=diff){
			res+=counts[r+1];
		}else{
			res+=counts[r];
		}
	}
	cout << res << "\n";
}

Compilation message

bobek.cpp: In function 'void setup1()':
bobek.cpp:34:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for (int j=0;j<v1.size();j++){
      |                ~^~~~~~~~~~
bobek.cpp: In function 'void setup2()':
bobek.cpp:45:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j=0;j<v2.size();j++){
      |                ~^~~~~~~~~~
bobek.cpp: In function 'void setIO(std::string)':
bobek.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 284 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3256 KB Output is correct
2 Correct 191 ms 23468 KB Output is correct
3 Correct 998 ms 69560 KB Output is correct
4 Correct 224 ms 26024 KB Output is correct
5 Correct 5 ms 1356 KB Output is correct
6 Correct 7 ms 1484 KB Output is correct
7 Correct 39 ms 9168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4552 KB Output is correct
2 Correct 41 ms 7780 KB Output is correct
3 Correct 87 ms 9664 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 2 ms 852 KB Output is correct
6 Correct 18 ms 4420 KB Output is correct
7 Correct 37 ms 8620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 15904 KB Output is correct
2 Correct 180 ms 20620 KB Output is correct
3 Correct 169 ms 20648 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 20 ms 6492 KB Output is correct
6 Correct 137 ms 18864 KB Output is correct
7 Correct 295 ms 35776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 899 ms 75648 KB Output is correct
2 Correct 54 ms 9684 KB Output is correct
3 Correct 17 ms 4776 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 707 ms 75700 KB Output is correct
7 Correct 34 ms 9172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 9680 KB Output is correct
2 Correct 324 ms 35900 KB Output is correct
3 Correct 16 ms 4776 KB Output is correct
4 Correct 17 ms 4760 KB Output is correct
5 Correct 25 ms 6476 KB Output is correct
6 Correct 37 ms 9692 KB Output is correct
7 Execution timed out 1091 ms 117088 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1100 ms 107620 KB Time limit exceeded
2 Halted 0 ms 0 KB -