Submission #98033

# Submission time Handle Problem Language Result Execution time Memory
98033 2019-02-19T23:55:40 Z shashwatchandra Ice Hockey World Championship (CEOI15_bobek) C++17
100 / 100
457 ms 20948 KB
/*input
1 99
100 1500 500 500 1000
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

vi one,two;
int a[45];
int n,m;
int haha;

void rec1(int i,int sum){
	 if(i == haha+1){one.pb(sum);return;}
	 rec1(i+1,sum);
	 rec1(i+1,sum+a[i]);
}

void rec2(int i,int sum){
	 if(i == n+1){two.pb(sum);return;}
	 rec2(i+1,sum);
	 rec2(i+1,sum+a[i]);
}

void solve(){
     cin >> n >> m;
     haha = (n+1)/2;
     RE(i,n)cin >> a[i];
     rec1(1,0);
     rec2(haha+1,0);
     sort(all(two));
     int ans = 0;
     REP(i,one.size()){
     	int lo = 0;
     	int hi = two.size()-1;
     	if(one[i] > m)continue;
     	int req = m-one[i];
     	while(lo < hi){
     		int mid = (lo+hi+1)/2;
     		if(two[mid] > req)hi = mid-1;
     		else lo = mid;
     	}
     	ans += (1+lo);
     }
     cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Compilation message

bobek.cpp: In function 'void solve()':
bobek.cpp:17:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,n) for (int i = 0; i < n; i++)
bobek.cpp:77:10:
      REP(i,one.size()){
          ~~~~~~~~~~~~               
bobek.cpp:77:6: note: in expansion of macro 'REP'
      REP(i,one.size()){
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2424 KB Output is correct
2 Correct 83 ms 5492 KB Output is correct
3 Correct 457 ms 20816 KB Output is correct
4 Correct 78 ms 5492 KB Output is correct
5 Correct 10 ms 1660 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 8 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2936 KB Output is correct
2 Correct 31 ms 2424 KB Output is correct
3 Correct 176 ms 10608 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 12 ms 1660 KB Output is correct
7 Correct 8 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 4468 KB Output is correct
2 Correct 147 ms 8560 KB Output is correct
3 Correct 138 ms 8608 KB Output is correct
4 Correct 2 ms 388 KB Output is correct
5 Correct 39 ms 8560 KB Output is correct
6 Correct 142 ms 20844 KB Output is correct
7 Correct 34 ms 8560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 16896 KB Output is correct
2 Correct 27 ms 2424 KB Output is correct
3 Correct 8 ms 1024 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 91 ms 16728 KB Output is correct
7 Correct 10 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2424 KB Output is correct
2 Correct 86 ms 5492 KB Output is correct
3 Correct 8 ms 1024 KB Output is correct
4 Correct 8 ms 1024 KB Output is correct
5 Correct 60 ms 8560 KB Output is correct
6 Correct 12 ms 2424 KB Output is correct
7 Correct 121 ms 20948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 20872 KB Output is correct
2 Correct 31 ms 2416 KB Output is correct
3 Correct 10 ms 1024 KB Output is correct
4 Correct 453 ms 20820 KB Output is correct
5 Correct 56 ms 10692 KB Output is correct
6 Correct 10 ms 1644 KB Output is correct
7 Correct 16 ms 2936 KB Output is correct