Submission #8511411


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
	#include <boost/multiprecision/cpp_int.hpp>
	#include <boost/multiprecision/cpp_dec_float.hpp>
	using bll = boost::multiprecision::cpp_int;
	using bdouble = boost::multiprecision::cpp_dec_float_100;
#endif
#ifdef LOCAL_DEV
	void debug_impl() { std::cerr << std::endl; }
	template<typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); }
	#define debug(...) std::cerr << std::boolalpha << "(" << #__VA_ARGS__ << ") ="; debug_impl(__VA_ARGS__); std::cerr << std::noboolalpha;
#else
	#define debug(...)
#endif
#ifdef LOCAL_TEST
	#define BOOST_STACKTRACE_USE_ADDR2LINE
	#define BOOST_STACKTRACE_ADDR2LINE_LOCATION /usr/local/opt/binutils/bin/addr2line
	#define _GNU_SOURCE
	#include <boost/stacktrace.hpp>
	template<typename T> class dvector : public std::vector<T> {
	public:
		dvector() : std::vector<T>() {}
		explicit dvector(size_t n, const T& value = T()) : std::vector<T>(n, value) {}
		dvector(const std::vector<T>& v) : std::vector<T>(v) {}
		dvector(const std::initializer_list<T> il) : std::vector<T>(il) {}
		dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {}
		dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {}
		T& operator[](size_t n) {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
		const T& operator[](size_t n) const {
			try { return this->at(n); } catch (const std::exception& e) {
				std::cerr << boost::stacktrace::stacktrace() << std::endl; return this->at(n);
			}
		}
	};
	class dbool {
	private:
		bool boolvalue;
	public:
		dbool() : boolvalue(false) {}
		dbool(bool b) : boolvalue(b) {}
		dbool(const dbool &b) : boolvalue(b.boolvalue) {}
		operator bool&() { return boolvalue; }
		operator const bool&() const { return boolvalue; }
	};
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector<T>& v) {
		for (int i = 0, len = v.size(); i < len; ++i){ s << v[i]; if (i < len - 1) s << "\t"; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const dvector< dvector<T> >& vv) {
		for (int i = 0, len = vv.size(); i < len; ++i){ s << vv[i] << std::endl; } return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}" << std::endl; return s; }
	template<typename T> std::ostream& operator<<(std::ostream& s, const std::multiset<T>& se) {
		s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr){ s << (*itr) << "\t"; } s << "}" << std::endl; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::map<T1, T2>& m) {
		s << "{" << std::endl; for (auto itr = m.begin(); itr != m.end(); ++itr){ s << "\t" << (*itr).first << " : " << (*itr).second << std::endl; } s << "}" << std::endl; return s; }
	template<typename T1, typename T2> std::ostream& operator<<(std::ostream& s, const std::pair<T1, T2>& p) { 
		return s << "(" << p.first << ", " << p.second << ")"; }
	#define vector dvector
	#define bool dbool
#endif
//#define int long long
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> &v) { for(ll i=0, N=v.size(); i<N; i++) std::cout << v[i] << " \n"[i==N-1]; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

/*-----8<-----template-----8<-----*/

/*-----8<-----library-----8<-----*/

const ll N_MAX = 1e5;
const ll K_MAX = 1<<30;
const ll A_I_MAX = 1<<30;
const ll B_I_MAX = 1e9;

ll N, K;
vector<ll> A;
vector<ll> B;

ll f(ll X){
	ll ans=0;
	rep(i,N){
		if((A[i]|X)==X)ans+=B[i];
	}
	return ans;
}

void solve() {
	scanf("%lld%lld", &N, &K);
	A.assign(N, 0);
	B.assign(N, 0);
	rep(i, N) scanf("%lld%lld", &A[i], &B[i]);

	ll keta=floor(log2(K))+1;

	ll ans = f(K);
	rep(i,keta){
		if (K & (1<<i)){
			ll t=K;
			t &= ~(1<<i);
			for(ll j=i-1;j>=0;j--)t|= (1<<j);
			ll tval=f(t);
			debug(i,t,tval);
			chmax(ans,tval);
		}
	}
	printf("%lld\n", ans);
}

// https://atcoder.jp/contests/tenka1-2017/tasks/tenka1_2017_d
signed main() {
	solve();
	return 0;
}

Submission Info

Submission Time
Task D - IntegerotS
User kyon2326
Language C++14 (GCC 5.4.1)
Score 500
Code Size 5198 Byte
Status AC
Exec Time 35 ms
Memory 2176 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:106:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &N, &K);
                           ^
./Main.cpp:109:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  rep(i, N) scanf("%lld%lld", &A[i], &B[i]);
                                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 63
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 27 ms 2176 KB
02.txt AC 24 ms 1792 KB
03.txt AC 24 ms 1792 KB
04.txt AC 25 ms 1792 KB
05.txt AC 23 ms 1792 KB
06.txt AC 23 ms 1792 KB
07.txt AC 24 ms 1792 KB
08.txt AC 24 ms 1792 KB
09.txt AC 24 ms 1792 KB
10.txt AC 25 ms 1792 KB
11.txt AC 28 ms 1792 KB
12.txt AC 28 ms 1792 KB
13.txt AC 30 ms 1792 KB
14.txt AC 31 ms 1792 KB
15.txt AC 28 ms 1792 KB
16.txt AC 27 ms 1792 KB
17.txt AC 30 ms 1792 KB
18.txt AC 26 ms 1792 KB
19.txt AC 28 ms 1792 KB
20.txt AC 28 ms 1792 KB
21.txt AC 29 ms 1792 KB
22.txt AC 26 ms 1792 KB
23.txt AC 26 ms 1792 KB
24.txt AC 25 ms 1792 KB
25.txt AC 24 ms 1792 KB
26.txt AC 27 ms 1792 KB
27.txt AC 25 ms 1792 KB
28.txt AC 25 ms 1792 KB
29.txt AC 26 ms 1792 KB
30.txt AC 26 ms 1792 KB
31.txt AC 25 ms 1792 KB
32.txt AC 26 ms 1792 KB
33.txt AC 25 ms 1792 KB
34.txt AC 24 ms 1792 KB
35.txt AC 24 ms 1792 KB
36.txt AC 25 ms 1792 KB
37.txt AC 23 ms 1792 KB
38.txt AC 23 ms 1792 KB
39.txt AC 24 ms 1792 KB
40.txt AC 25 ms 1792 KB
41.txt AC 23 ms 1792 KB
42.txt AC 23 ms 1792 KB
43.txt AC 22 ms 1792 KB
44.txt AC 23 ms 1792 KB
45.txt AC 23 ms 1792 KB
46.txt AC 23 ms 1792 KB
47.txt AC 35 ms 1792 KB
48.txt AC 35 ms 1792 KB
49.txt AC 23 ms 2048 KB
50.txt AC 18 ms 1792 KB
51.txt AC 1 ms 256 KB
52.txt AC 1 ms 256 KB
53.txt AC 1 ms 256 KB
54.txt AC 1 ms 256 KB
55.txt AC 1 ms 256 KB
56.txt AC 1 ms 256 KB
57.txt AC 1 ms 256 KB
58.txt AC 1 ms 256 KB
59.txt AC 1 ms 256 KB
60.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB