QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139442 | #5259. Skills in Pills | tselmegkh# | TL | 0ms | 0kb | C++20 | 2.5kb | 2023-08-13 15:53:32 | 2023-08-13 15:53:36 |
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
const int N = 2e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
int dp[1000006][2];
int n, i, j;
int_fast16_t doit(int lst, int type){
if(dp[lst][type] != 0) return dp[lst][type];
if(type == 1 && lst + i - 1 > n && lst + j > n) return 0;
if(type == 0 && lst + j - 1 > n && lst + i > n) return 0;
if(type == 1){
// i, j
int cnt = 0;
while(true){
cnt += j;
if((cnt + 1) % i == 0) break;
}
if(lst + cnt > n){
dp[lst][type] = (n - lst + 1) / i + (n - lst) / j;
return dp[lst][type];
}
else{
dp[lst][type] = ((cnt + 1 ) / i + cnt / j) + min(doit(lst + cnt, 0), doit(lst + cnt, 1));
return dp[lst][type];
}
}
else{
// j i
int cnt = 0;
while(true){
cnt += i;
if((cnt + 1) % j == 0) break;
}
if(cnt + lst > n){
dp[lst][type] = (n - lst + 1) / i + (n - lst) / j;
return dp[lst][type];
}
else{
dp[lst][type] = ((cnt + 1 ) / j + cnt / i) + min(doit(lst + cnt, 0), doit(lst + cnt, 1));
return dp[lst][type];
}
}
return dp[lst][type];
}
void solve(){
cin >> i >> j >> n;
if(i == j){
if(n % i == 0){
cout << (n / i) * 2 << '\n';
}
else{
if(n % i + 1 >= i){
cout << (n / i) * 2 + 1 << '\n';
}
else cout << (n / i) * 2 << '\n';
}
return;
}
int lst = 0;
while(true){
lst += i;
if(lst % j == 0){
break;
}
}
int ans = 0;
if(lst >= n){
ans = n / i + n / j;
cout << ans << '\n';
return;
}
else{
ans = min(doit(lst, 1), doit(lst, 0)) + lst / i + lst / j;
cout << ans << '\n';
return;
}
return;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t = 1;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 9 20