Submission #71976
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) begin(x), end(x) #define Fixed fixed << setprecision(12) #define int int_fast64_t using pii = pair< int , int >; constexpr int32_t INF = 0x3f3f3f3f; constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fll; constexpr int mod1 = 1e9+7; constexpr int mod2 = 998244353; template < class Func> class FixPoint : Func { public : explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template < class ... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(* this , std::forward<Args>(args)...); } }; template < class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func>{forward<Func>(f)}; } template < class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true ); } template < class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true ); } template < class T> using max_heap = priority_queue<T>; template < class T> using min_heap = priority_queue<T,vector<T>,greater<T> >; template < class A, class B> using umap = unordered_map<A,B>; template < class T> inline void bye(T x) { cout << x << '\n' ; exit (0); } inline int square( int a){ return a * a;} inline int updiv( int a, int b){ return (a + b - 1) / b; } constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; signed main( void ){ cin.tie(nullptr); ios_base::sync_with_stdio( false ); int n, m; cin >> n >> m; vector< int > a(m), b(m); for ( int i = 0; i < m; ++i) { cin >> a[i] >> b[i]; } a.insert(a.begin(), 0); b.insert(b.begin(), 0); a.emplace_back(n + 1); b.emplace_back(LINF); m += 2; int sum = 0, res = 0; for ( int i = 1; i < m; ++i) { int len = a[i] - a[i - 1]; int diff = b[i] - b[i - 1]; chmax(res, sum + b[i - 1] * (len - 1) + len * (len - 1) / 2); if (len < abs (diff)) break ; int u = (len + diff) / 2; int d = (len - diff) / 2; sum += u * b[i - 1]; sum += d * b[i]; sum += u * (u + 1) / 2; sum += d * (d - 1) / 2; if (u + d != len) { sum += b[i - 1] + u; } } cout << res << '\n' ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1541 - 募金街道 |
ユーザー名 | syoribu |
投稿日時 | 2022-08-30 09:27:40 |
言語 | C++17 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 2471 Byte |
最大実行時間 | 53 ms |
最大メモリ使用量 | 18108 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 10 / 10 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1 | AC | 26 ms | 604 KB |
1
|
in2 | AC | 27 ms | 2048 KB |
1
|
in3 | AC | 26 ms | 15692 KB |
1
|
in4 | AC | 24 ms | 15644 KB |
1
|
in5 | AC | 22 ms | 15724 KB |
1
|
in6 | AC | 23 ms | 15680 KB |
1
|
in7 | AC | 21 ms | 15632 KB |
1
|
in8 | AC | 25 ms | 15712 KB |
1
|
in9 | AC | 22 ms | 15668 KB |
1
|
in10 | AC | 22 ms | 432 KB |
1
|
in11 | AC | 24 ms | 516 KB |
1
|
in12 | AC | 22 ms | 468 KB |
1
|
in13 | AC | 21 ms | 552 KB |
1
|
in14 | AC | 20 ms | 504 KB |
1
|
in15 | AC | 19 ms | 584 KB |
1
|
in16 | AC | 18 ms | 496 KB |
1
|
in17 | AC | 19 ms | 660 KB |
1
|
in18 | AC | 35 ms | 576 KB |
1
|
in19 | AC | 43 ms | 4460 KB |
1
|
in20 | AC | 46 ms | 6484 KB |
1
|
in21 | AC | 19 ms | 4072 KB |
1
|
in22 | AC | 23 ms | 4160 KB |
1
|
in23 | AC | 23 ms | 4244 KB |
1
|
in24 | AC | 35 ms | 8428 KB |
1
|
in25 | AC | 38 ms | 10360 KB |
1
|
in26 | AC | 43 ms | 12300 KB |
1
|
in27 | AC | 40 ms | 14104 KB |
1
|
in28 | AC | 53 ms | 16044 KB |
1
|
in29 | AC | 44 ms | 18108 KB |
1
|