Submission #61900445
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;using ll = long long;using ull = unsigned long long;int main() {ll n, m;cin >> n >> m;vector<ll> a(n);for (ll i = 0; i < n; ++i) cin >> a[i];ull l = 0, r = 1LL << 60;while (r - l > 1) {ull mid = (r + l) / 2;ull c = 0;bool overflow = false;for (ll i = 0; i < n; ++i) {ull x = (mid / a[i] + 1) / 2;if (x > (1LL << 30)) { // 2^30を超えるとオーバーフローの可能性overflow = true;
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; int main() { ll n, m; cin >> n >> m; vector<ll> a(n); for (ll i = 0; i < n; ++i) cin >> a[i]; ull l = 0, r = 1LL << 60; while (r - l > 1) { ull mid = (r + l) / 2; ull c = 0; bool overflow = false; for (ll i = 0; i < n; ++i) { ull x = (mid / a[i] + 1) / 2; if (x > (1LL << 30)) { // 2^30を超えるとオーバーフローの可能性 overflow = true; break; } ull temp = x * x; if (temp > ULLONG_MAX / a[i]) { // オーバーフロー検出 overflow = true; break; } c += temp * a[i]; if (c >= m) break; // これ以上計算する必要はない } if (overflow || c >= m) r = mid; else l = mid; } ull res = 0, cost = 0; for (ll i = 0; i < n; ++i) { ull x = (l / a[i] + 1) / 2; res += x; if (x > 0) { ull temp = x * x; if (temp > ULLONG_MAX / a[i]) continue; // オーバーフローなら無視 cost += temp * a[i]; } } for (ll i = 0; i < n; ++i) { ull x = ((l + 1) / a[i] + 1) / 2; if (x > 0 && l + 1 == (2 * x - 1) * a[i]) { ull temp = (2 * x - 1) * a[i]; if (cost + temp <= m) { res++; cost += temp; } } } cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Square Price |
User | po1 |
Language | C++ 20 (gcc 12.2) |
Score | 475 |
Code Size | 1646 Byte |
Status | AC |
Exec Time | 77 ms |
Memory | 4904 KiB |
Compile Error
Main.cpp: In function ‘int main()’: Main.cpp:30:19: warning: comparison of integer expressions of different signedness: ‘ull’ {aka ‘long long unsigned int’} and ‘ll’ {aka ‘long long int’} [-Wsign-compare] 30 | if (c >= m) break; // これ以上計算する必要はない | ~~^~~~ Main.cpp:33:27: warning: comparison of integer expressions of different signedness: ‘ull’ {aka ‘long long unsigned int’} and ‘ll’ {aka ‘long long int’} [-Wsign-compare] 33 | if (overflow || c >= m) r = mid; | ~~^~~~ Main.cpp:53:29: warning: comparison of integer expressions of different signedness: ‘ull’ {aka ‘long long unsigned int’} and ‘ll’ {aka ‘long long int’} [-Wsign-compare] 53 | if (cost + temp <= m) { | ~~~~~~~~~~~~^~~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 475 / 475 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3528 KiB |
00_sample_01.txt | AC | 1 ms | 3468 KiB |
01_random_00.txt | AC | 72 ms | 4748 KiB |
01_random_01.txt | AC | 72 ms | 4732 KiB |
01_random_02.txt | AC | 72 ms | 4744 KiB |
01_random_03.txt | AC | 71 ms | 4812 KiB |
01_random_04.txt | AC | 71 ms | 4728 KiB |
01_random_05.txt | AC | 70 ms | 4768 KiB |
01_random_06.txt | AC | 72 ms | 4904 KiB |
01_random_07.txt | AC | 73 ms | 4740 KiB |
01_random_08.txt | AC | 72 ms | 4688 KiB |
01_random_09.txt | AC | 72 ms | 4672 KiB |
01_random_10.txt | AC | 7 ms | 3480 KiB |
01_random_11.txt | AC | 63 ms | 4460 KiB |
01_random_12.txt | AC | 6 ms | 3588 KiB |
01_random_13.txt | AC | 14 ms | 3524 KiB |
01_random_14.txt | AC | 45 ms | 4212 KiB |
01_random_15.txt | AC | 68 ms | 4816 KiB |
01_random_16.txt | AC | 35 ms | 3876 KiB |
01_random_17.txt | AC | 22 ms | 3596 KiB |
01_random_18.txt | AC | 56 ms | 4108 KiB |
01_random_19.txt | AC | 61 ms | 4472 KiB |
01_random_20.txt | AC | 34 ms | 4812 KiB |
01_random_21.txt | AC | 77 ms | 4732 KiB |
01_random_22.txt | AC | 1 ms | 3600 KiB |
01_random_23.txt | AC | 1 ms | 3468 KiB |