提出 #34167063
ソースコード 拡げる
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("popcnt")
using namespace std;
using namespace __gnu_pbds;
template <typename t>
using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
// #pragma gcc optimize("ofast")
// #pragma gcc target("avx,avx2,fma")
#define int long long
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
#define fi first
#define se second
// const int mod = 1e9 + 7;
const int mod=998'244'353;
const long long INF = 2e18 + 10;
// const int INF=1e9+10;
#define readv(x, n) \
vector<int> x(n); \
for (auto &i : x) \
cin >> i;
template <typename t>
using v = vector<t>;
template <typename t>
using vv = vector<vector<t>>;
template <typename t>
using vvv = vector<vector<vector<t>>>;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<vector<double>> vvd;
typedef pair<int, int> pii;
int multiply(int a, int b, int in_mod) { return (int)(1ll * a * b % in_mod); }
int mult_identity(int a) { return 1; }
const double pi = acosl(-1);
auto power(auto a, auto b, const int in_mod)
{
auto prod = mult_identity(a);
auto mult = a % in_mod;
while (b != 0)
{
if (b % 2)
{
prod = multiply(prod, mult, in_mod);
}
if(b/2)
mult = multiply(mult, mult, in_mod);
b /= 2;
}
return prod;
}
auto mod_inv(auto q, const int in_mod)
{
return power(q, in_mod - 2, in_mod);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define stp cout << fixed << setprecision(20);
const int MAXN=5e5+10;
vector<int> fac(MAXN);
vector<int> infac(MAXN);
void build_factorial()
{
fac[0]=1;
infac[0]=1;
for(int i=1;i<MAXN;i++)
{
fac[i]=(fac[i-1]*i)%mod;
}
infac[MAXN-1] = power(fac[MAXN -1], mod - 2, mod);
for(int i= MAXN-2;i>=0;i--)
{
infac[i] = infac[i+1] *(i + 1) % mod;
}
}
int ncr(int n, int r)
{
if(n< r)
return 0;
return 1LL*fac[n] * infac[r] %mod * infac[n-r]%mod;
}
auto cmp(int a, int b)
{
int len_a = to_string(a).size();
int len_b = to_string(b).size();
if(len_b != len_a)
return len_a < len_b;
return a < b;
};
void solv()
{
int n, m, k;
cin>>n>>m>>k;
readv(a,n);
sort(all(a));
int ans = 0;
int free_guys = 0;
for(int bit = 30;bit>=0;bit--)
{
vector<int> on, off;
for(auto i:a)
if( i & (1<<bit))
on.push_back(i);
else
off.push_back(i);
if(on.size()>=k)
{
ans |= (1<<bit);
a = on;
}
else
{
sort(all(off));
int needed = k - on.size();
reverse(all(off));
int sm = accumulate(off.begin(), off.begin() + needed, (int)0);
int need = (needed * (1<<bit)) - sm;
if( need <= m)
{
m -= need;
ans |= (1<<bit);
while(on.size() <=k)
on.push_back((1<<bit));
a = on;
}else{
//continue;
}
}
for(auto &i:a)
if( i& (1<<bit))
i ^= (1<<bit);
}
cout<<ans<<endl;
}
void solve()
{
int t = 1;
// cin>>t;
while(t--)
{
solv();
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cerr.tie(NULL);
#ifdef ONLINE_JUDGE
#ifdef ASC
namespace fs = std::filesystem;
std::string path = "./";
string filename;
for (const auto & entry : fs::directory_iterator(path)){
if( entry.path().extension().string() == ".in"){
filename = entry.path().filename().stem().string();
}
}
if(filename != ""){
string input_file = filename +".in";
string output_file = filename +".out";
if (fopen(input_file.c_str(), "r"))
{
freopen(input_file.c_str(), "r", stdin);
freopen(output_file.c_str(), "w", stdout);
}
}
#endif
#endif
auto clk = clock();
// -------------------------------------Code starts here---------------------------------------------------------------------
signed t = 1;
// cin >> t;
for (signed test = 1; test <= t; test++)
{
// cout<<"Case #"<<test<<": ";
solve();
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
#ifndef ONLINE_JUDGE
cerr << fixed << setprecision(6) << "\nTime: " << ((float)clk) / CLOCKS_PER_SEC << "\n";
#endif
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Plus and AND |
| ユーザ | Wernier |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 5247 Byte |
| 結果 | AC |
| 実行時間 | 213 ms |
| メモリ | 19152 KiB |
コンパイルエラー
./Main.cpp: In function ‘long long int mult_identity(long long int)’:
./Main.cpp:63:23: warning: unused parameter ‘a’ [-Wunused-parameter]
63 | int mult_identity(int a) { return 1; }
| ^
./Main.cpp: At global scope:
./Main.cpp:71:12: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
71 | auto power(auto a, auto b, const int in_mod)
| ^~~~
./Main.cpp:71:20: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
71 | auto power(auto a, auto b, const int in_mod)
| ^~~~
./Main.cpp:88:14: warning: use of ‘auto’ in parameter declaration only available with ‘-fconcepts’
88 | auto mod_inv(auto q, const int in_mod)
| ^~~~
./Main.cpp: In function ‘void solv()’:
./Main.cpp:160:21: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
160 | if(on.size()>=k)
| ~~~~~~~~~^~~
./Main.cpp:180:33: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
180 | while(on.size() <=k)
| ~~~~~~~~~~^~~
./Main.cpp:150:9: warning: unused variable ‘free_guys’ [-Wunused-variable]
150 | int free_guys = 0;
| ^~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| example_00.txt | AC | 12 ms | 10960 KiB |
| example_01.txt | AC | 10 ms | 10944 KiB |
| test_00.txt | AC | 132 ms | 15628 KiB |
| test_01.txt | AC | 213 ms | 18076 KiB |
| test_02.txt | AC | 142 ms | 15684 KiB |
| test_03.txt | AC | 122 ms | 14684 KiB |
| test_04.txt | AC | 37 ms | 11852 KiB |
| test_05.txt | AC | 100 ms | 15292 KiB |
| test_06.txt | AC | 72 ms | 13052 KiB |
| test_07.txt | AC | 37 ms | 12592 KiB |
| test_08.txt | AC | 45 ms | 13088 KiB |
| test_09.txt | AC | 88 ms | 15112 KiB |
| test_10.txt | AC | 12 ms | 10940 KiB |
| test_11.txt | AC | 29 ms | 11792 KiB |
| test_12.txt | AC | 37 ms | 12184 KiB |
| test_13.txt | AC | 16 ms | 11600 KiB |
| test_14.txt | AC | 118 ms | 14636 KiB |
| test_15.txt | AC | 32 ms | 12400 KiB |
| test_16.txt | AC | 25 ms | 11644 KiB |
| test_17.txt | AC | 20 ms | 11588 KiB |
| test_18.txt | AC | 158 ms | 17252 KiB |
| test_19.txt | AC | 61 ms | 14632 KiB |
| test_20.txt | AC | 175 ms | 16180 KiB |
| test_21.txt | AC | 158 ms | 15972 KiB |
| test_22.txt | AC | 114 ms | 15452 KiB |
| test_23.txt | AC | 122 ms | 15384 KiB |
| test_24.txt | AC | 99 ms | 15284 KiB |
| test_25.txt | AC | 52 ms | 15136 KiB |
| test_26.txt | AC | 194 ms | 17344 KiB |
| test_27.txt | AC | 160 ms | 16260 KiB |
| test_28.txt | AC | 63 ms | 15196 KiB |
| test_29.txt | AC | 157 ms | 16368 KiB |
| test_30.txt | AC | 97 ms | 14592 KiB |
| test_31.txt | AC | 63 ms | 12444 KiB |
| test_32.txt | AC | 104 ms | 14704 KiB |
| test_33.txt | AC | 32 ms | 11440 KiB |
| test_34.txt | AC | 118 ms | 15076 KiB |
| test_35.txt | AC | 158 ms | 15948 KiB |
| test_36.txt | AC | 58 ms | 12760 KiB |
| test_37.txt | AC | 115 ms | 15236 KiB |
| test_38.txt | AC | 14 ms | 11292 KiB |
| test_39.txt | AC | 18 ms | 11448 KiB |
| test_40.txt | AC | 143 ms | 16472 KiB |
| test_41.txt | AC | 60 ms | 12692 KiB |
| test_42.txt | AC | 73 ms | 14768 KiB |
| test_43.txt | AC | 89 ms | 13932 KiB |
| test_44.txt | AC | 30 ms | 11956 KiB |
| test_45.txt | AC | 53 ms | 13840 KiB |
| test_46.txt | AC | 118 ms | 15708 KiB |
| test_47.txt | AC | 188 ms | 19108 KiB |
| test_48.txt | AC | 33 ms | 11708 KiB |
| test_49.txt | AC | 55 ms | 13020 KiB |
| test_50.txt | AC | 67 ms | 12812 KiB |
| test_51.txt | AC | 141 ms | 16732 KiB |
| test_52.txt | AC | 17 ms | 11352 KiB |
| test_53.txt | AC | 192 ms | 19152 KiB |
| test_54.txt | AC | 90 ms | 14088 KiB |
| test_55.txt | AC | 146 ms | 16840 KiB |