Submission #57070956
Source Code Expand
Copy
#include<bits/stdc++.h>#define int long long#define pb push_back#define fi first#define se second#define pii pair<int, int>using namespace std;inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9')x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();return x * f; }int a, t, n;bool check(int m, int flag){int l = ((t + 1) % 3 == 0 ? (t + 1) : ((t + 2) % 3 == 0 ? (t + 2) : (t + 3)));int r = ((m) % 3 == 0 ? (m) : ((m - 1) % 3 == 0 ? (m - 1) : (m - 2)));// int k = ((t + 1 + m) * (m - t) >> 1) + ((l + r) * ((r - l) / 3 + 1) >> 1);// cout << l << " " << r << " " << k << "\n";int k = ((r - l) / 3 + 1) * 2 + m - t;// cout << k << "\n";return k >= flag;
#include<bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair<int, int> using namespace std; inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9')x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();return x * f; } int a, t, n; bool check(int m, int flag){ int l = ((t + 1) % 3 == 0 ? (t + 1) : ((t + 2) % 3 == 0 ? (t + 2) : (t + 3))); int r = ((m) % 3 == 0 ? (m) : ((m - 1) % 3 == 0 ? (m - 1) : (m - 2))); // int k = ((t + 1 + m) * (m - t) >> 1) + ((l + r) * ((r - l) / 3 + 1) >> 1); // cout << l << " " << r << " " << k << "\n"; int k = ((r - l) / 3 + 1) * 2 + m - t; // cout << k << "\n"; return k >= flag; } int solve(int k){ int l = t + 1, r = 1e15, res = t; while(l <= r){ int mid = l + r >> 1; if(check(mid, k)){ r = mid - 1; res = mid; } else{ l = mid + 1; } } return res; } signed main(){ ios ::sync_with_stdio (false); cin.tie(NULL), cout.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i){ cin >> a; t = solve(a); } cout << t << "\n"; // check(3, 1); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Triple Attack |
User | yanjunhao |
Language | C++ 20 (gcc 12.2) |
Score | 300 |
Code Size | 1227 Byte |
Status | AC |
Exec Time | 85 ms |
Memory | 3616 KB |
Compile Error
Main.cpp: In function ‘long long int solve(long long int)’: Main.cpp:27:29: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses] 27 | int mid = l + r >> 1; | ~~^~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt, sample_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
random_01.txt | AC | 85 ms | 3480 KB |
random_02.txt | AC | 75 ms | 3400 KB |
random_03.txt | AC | 85 ms | 3464 KB |
random_04.txt | AC | 24 ms | 3496 KB |
random_05.txt | AC | 85 ms | 3476 KB |
random_06.txt | AC | 42 ms | 3488 KB |
random_07.txt | AC | 85 ms | 3476 KB |
random_08.txt | AC | 26 ms | 3484 KB |
random_09.txt | AC | 84 ms | 3480 KB |
random_10.txt | AC | 54 ms | 3428 KB |
random_11.txt | AC | 84 ms | 3400 KB |
random_12.txt | AC | 22 ms | 3540 KB |
random_13.txt | AC | 85 ms | 3472 KB |
random_14.txt | AC | 76 ms | 3424 KB |
random_15.txt | AC | 85 ms | 3424 KB |
random_16.txt | AC | 21 ms | 3484 KB |
random_17.txt | AC | 85 ms | 3484 KB |
random_18.txt | AC | 10 ms | 3376 KB |
random_19.txt | AC | 38 ms | 3616 KB |
random_20.txt | AC | 15 ms | 3452 KB |
random_21.txt | AC | 79 ms | 3476 KB |
random_22.txt | AC | 1 ms | 3480 KB |
sample_01.txt | AC | 1 ms | 3416 KB |
sample_02.txt | AC | 1 ms | 3412 KB |
sample_03.txt | AC | 1 ms | 3396 KB |