結果

問題 No.3331 Consecutive Cubic Sum
コンテスト
ユーザー toppo57
提出日時 2026-10-27 22:14:53
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 5,000 ms
+ 345µs
コード長 738 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,441 ms
コンパイル使用メモリ 175,340 KB
実行使用メモリ 13,052 KB
最終ジャッジ日時 2026-10-27 22:15:01
合計ジャッジ時間 4,787 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <utility>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin>>N;
    vector<ll> cube;
    for (ll i=1;i*i*i<=N;i++) cube.push_back(i*i*i);
    int M = cube.size();

    ll cnt = 0;
    vector<pii> ans;
    ll sum = 0;
    int right = 0;
    for (int left=0;left<M;left++){
        while(right<M&&sum+cube[right]<=N) sum += cube[right++];
        if (sum==N){
            cnt++;
            ans.push_back({left+1, right});
        }
        if (right==left) right++;
        else sum -= cube[left];
    }

    cout << cnt << "\n";
    for (auto [l, r]: ans) cout << l << " " << r << "\n";
}
0