CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)
B. Candies
关于b题,昨天大概是脑子被夹了,所以没想到吧,emmm
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define deb2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y <<endl
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> PII;
int a[N];
void run()
{
int n; cin >> n;
if(n % 2 == 0) cout << -1 << endl;
else {
int x= n, cnt = 0, i;
while(x) {
x >>= 1;
cnt += 1;
}
cout << cnt - 1<< endl;
for (i = cnt-1; i >= 1; i-- ) {
x = n >> i;
if(x & 1) cout <<2 << ' ';
else cout << 1 <<' ';
}
cout << endl;
}
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
cout << fixed; cout.precision(18);
int T = 1;
cin >> T;
while(T -- ) run();
}
C. Make It Permutation
终于不T了,因为,其实复杂度是n平方log,没想清楚
过了,真无语啊,这都能行
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define deb2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y <<endl
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> PII;
int a[N];
set<int> st;
map<int, int> mp;
int n, c, d;
void run()
{
st.clear();
mp.clear();
cin >> n >> c >> d;
int i, j;
for (i = 1; i <= n; i ++) {
cin >> a[i];
st.insert(a[i]);
}
int k = 0;
for (auto t : st){
mp[t] = ++k;
}
sort(a + 1, a + n + 1);
ll minx = 100000000000000000;
int t = 0, t2 = 0;
for (i = 1; i <= n; i ++ ) {
int k = mp[a[i]];
t = a[i] - k;
t2 = (n-k);
if(t < 0) continue;
ll res = (ll)d*t + c*t2;
// deb2(t, t2);
minx = min(minx, res);
}
minx = min((ll)c*n+d, minx);
cout << minx << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0);
// cout << fixed; cout.precision(18);
int T = 1;
cin >> T;
while(T -- ) run();
}