QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726688 | #3622. Weighty Tomes | nickbelov# | AC ✓ | 30ms | 7200kb | C++20 | 3.3kb | 2024-11-09 05:35:37 | 2024-11-09 05:35:37 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
ostream_iterator<T> oit(const string &s = " "){ return ostream_iterator<T>(cout,s.c_str()); }
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
#define A(a) begin(a),end(a)
inline auto len = ranges::ssize;
struct chash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
typedef vector<ll> vll;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
constexpr ll NN = 2e5, M = 1000000007, L = 20;
ll f1[NN], f2[NN];
ll inv(ll a, ll b=M) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } // inv a mod b
ll choose(ll n, ll k) { return f1[n] * f2[k] % M * f2[n - k] % M; } // n choose k
vector<vector<int>> cache;
int dp(int n, int m) {
if (n == 0) return 0;
if (n == 1) return 0;
if (m == 0) return M;
auto& x = cache[n][m];
if (x == -1) {
int l = 0;
int r = n;
while (l < r-1) {
int mid = (l + r) / 2;
int x1 = dp(mid, m-1);
int x2 = dp(n-mid, m);
if (x1 == x2) return x = x1+1;
else if (x1 < x2) {
l = mid;
} else {
r = mid;
}
}
x = min(max(dp(l, m-1), dp(n-l, m)), max(dp(r, m-1), dp(n-r, m)))+1;
}
return x;
}
void run()
{
int n, m;
cin >> n >> m;
cache.resize(n+2, vi(m+1, -1));
int best = dp(n+1,m);
cout << best << " ";
int l = 0;
for (int k : rep(0, n+1)) {
if (max(dp(k, m-1), dp(n-k+1, m))+1 == best) {
l = k;
break;
}
}
int r = n;
for (int k : per(0, n+1)) {
if (max(dp(k, m-1), dp(n-k+1, m))+1 == best) {
r = k;
break;
}
}
if (l == r)
cout << l << endl;
else
cout << l << "-" << r << endl;
}
int main()
{
//KING OF THE WORLD...... U.W.T.B
cin.tie(0);
ios_base::sync_with_stdio(false);
f1[0] = 1;
f2[0] = 1;
for (int i = 1; i < NN; i++) {
f1[i] = f1[i - 1] * i % M;
f2[i] = inv(f1[i], M);
}
int t=1; while(t--) run();
}
詳細信息
Test #1:
score: 100
Accepted
time: 29ms
memory: 6724kb
input:
3 1
output:
3 1
result:
ok single line: '3 1'
Test #2:
score: 0
Accepted
time: 30ms
memory: 6724kb
input:
3 2
output:
2 2
result:
ok single line: '2 2'
Test #3:
score: 0
Accepted
time: 25ms
memory: 6660kb
input:
4 2
output:
3 1-3
result:
ok single line: '3 1-3'
Test #4:
score: 0
Accepted
time: 30ms
memory: 7200kb
input:
5000 20
output:
13 905-4096
result:
ok single line: '13 905-4096'
Test #5:
score: 0
Accepted
time: 26ms
memory: 7120kb
input:
5000 10
output:
13 918-4017
result:
ok single line: '13 918-4017'
Test #6:
score: 0
Accepted
time: 30ms
memory: 6968kb
input:
5000 5
output:
16 57-1941
result:
ok single line: '16 57-1941'
Test #7:
score: 0
Accepted
time: 30ms
memory: 6988kb
input:
5000 1
output:
5000 1
result:
ok single line: '5000 1'
Test #8:
score: 0
Accepted
time: 30ms
memory: 6964kb
input:
4000 20
output:
12 1953-2048
result:
ok single line: '12 1953-2048'
Test #9:
score: 0
Accepted
time: 30ms
memory: 7104kb
input:
4000 10
output:
12 1954-2036
result:
ok single line: '12 1954-2036'
Test #10:
score: 0
Accepted
time: 30ms
memory: 6960kb
input:
4000 5
output:
15 528-1471
result:
ok single line: '15 528-1471'
Test #11:
score: 0
Accepted
time: 30ms
memory: 6888kb
input:
4000 1
output:
4000 1
result:
ok single line: '4000 1'
Test #12:
score: 0
Accepted
time: 25ms
memory: 6940kb
input:
3000 20
output:
12 953-2048
result:
ok single line: '12 953-2048'
Test #13:
score: 0
Accepted
time: 30ms
memory: 6864kb
input:
3000 10
output:
12 954-2036
result:
ok single line: '12 954-2036'
Test #14:
score: 0
Accepted
time: 30ms
memory: 6884kb
input:
3000 5
output:
14 621-1093
result:
ok single line: '14 621-1093'
Test #15:
score: 0
Accepted
time: 29ms
memory: 7076kb
input:
3000 1
output:
3000 1
result:
ok single line: '3000 1'
Test #16:
score: 0
Accepted
time: 29ms
memory: 6664kb
input:
100 1
output:
100 1
result:
ok single line: '100 1'
Test #17:
score: 0
Accepted
time: 29ms
memory: 6916kb
input:
100 2
output:
14 9-14
result:
ok single line: '14 9-14'
Test #18:
score: 0
Accepted
time: 29ms
memory: 6744kb
input:
100 3
output:
9 8-37
result:
ok single line: '9 8-37'
Test #19:
score: 0
Accepted
time: 29ms
memory: 6680kb
input:
100 4
output:
8 2-64
result:
ok single line: '8 2-64'
Test #20:
score: 0
Accepted
time: 26ms
memory: 6880kb
input:
100 5
output:
7 38-57
result:
ok single line: '7 38-57'
Test #21:
score: 0
Accepted
time: 25ms
memory: 6948kb
input:
100 6
output:
7 37-63
result:
ok single line: '7 37-63'
Test #22:
score: 0
Accepted
time: 29ms
memory: 6948kb
input:
100 7
output:
7 37-64
result:
ok single line: '7 37-64'
Test #23:
score: 0
Accepted
time: 29ms
memory: 6724kb
input:
100 8
output:
7 37-64
result:
ok single line: '7 37-64'
Test #24:
score: 0
Accepted
time: 29ms
memory: 6960kb
input:
100 9
output:
7 37-64
result:
ok single line: '7 37-64'
Test #25:
score: 0
Accepted
time: 29ms
memory: 6752kb
input:
100 10
output:
7 37-64
result:
ok single line: '7 37-64'
Test #26:
score: 0
Accepted
time: 25ms
memory: 6688kb
input:
100 11
output:
7 37-64
result:
ok single line: '7 37-64'
Test #27:
score: 0
Accepted
time: 21ms
memory: 6728kb
input:
100 12
output:
7 37-64
result:
ok single line: '7 37-64'
Test #28:
score: 0
Accepted
time: 25ms
memory: 6916kb
input:
100 13
output:
7 37-64
result:
ok single line: '7 37-64'
Test #29:
score: 0
Accepted
time: 29ms
memory: 6684kb
input:
100 14
output:
7 37-64
result:
ok single line: '7 37-64'
Test #30:
score: 0
Accepted
time: 26ms
memory: 6748kb
input:
100 15
output:
7 37-64
result:
ok single line: '7 37-64'
Test #31:
score: 0
Accepted
time: 29ms
memory: 6948kb
input:
100 16
output:
7 37-64
result:
ok single line: '7 37-64'
Test #32:
score: 0
Accepted
time: 30ms
memory: 6884kb
input:
100 17
output:
7 37-64
result:
ok single line: '7 37-64'
Test #33:
score: 0
Accepted
time: 29ms
memory: 6672kb
input:
100 18
output:
7 37-64
result:
ok single line: '7 37-64'
Test #34:
score: 0
Accepted
time: 29ms
memory: 6924kb
input:
100 19
output:
7 37-64
result:
ok single line: '7 37-64'
Test #35:
score: 0
Accepted
time: 22ms
memory: 6956kb
input:
100 20
output:
7 37-64
result:
ok single line: '7 37-64'
Test #36:
score: 0
Accepted
time: 29ms
memory: 6672kb
input:
10 5
output:
4 3-8
result:
ok single line: '4 3-8'
Test #37:
score: 0
Accepted
time: 29ms
memory: 6944kb
input:
10 2
output:
4 4
result:
ok single line: '4 4'
Test #38:
score: 0
Accepted
time: 29ms
memory: 6740kb
input:
10 10
output:
4 3-8
result:
ok single line: '4 3-8'
Test #39:
score: 0
Accepted
time: 29ms
memory: 6748kb
input:
10 15
output:
4 3-8
result:
ok single line: '4 3-8'
Test #40:
score: 0
Accepted
time: 26ms
memory: 6672kb
input:
10 20
output:
4 3-8
result:
ok single line: '4 3-8'
Test #41:
score: 0
Accepted
time: 30ms
memory: 6848kb
input:
2441 3
output:
25 117-301
result:
ok single line: '25 117-301'
Test #42:
score: 0
Accepted
time: 30ms
memory: 6716kb
input:
2011 3
output:
23 218-254
result:
ok single line: '23 218-254'
Test #43:
score: 0
Accepted
time: 26ms
memory: 6924kb
input:
2945 13
output:
12 898-2048
result:
ok single line: '12 898-2048'
Test #44:
score: 0
Accepted
time: 26ms
memory: 6928kb
input:
3449 11
output:
12 1402-2047
result:
ok single line: '12 1402-2047'
Test #45:
score: 0
Accepted
time: 29ms
memory: 6940kb
input:
3019 11
output:
12 972-2047
result:
ok single line: '12 972-2047'
Test #46:
score: 0
Accepted
time: 30ms
memory: 7160kb
input:
3952 1
output:
3952 1
result:
ok single line: '3952 1'