結果

問題 No.853 河原の石
ユーザー Enjapma_kyoproEnjapma_kyopro
提出日時 2019-07-06 17:39:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 241 ms / 3,153 ms
コード長 3,846 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 93,744 KB
実行使用メモリ 17,264 KB
最終ジャッジ日時 2023-08-03 12:36:07
合計ジャッジ時間 5,253 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
16,912 KB
testcase_01 AC 7 ms
16,876 KB
testcase_02 AC 6 ms
16,876 KB
testcase_03 AC 6 ms
17,244 KB
testcase_04 AC 6 ms
16,956 KB
testcase_05 AC 7 ms
17,036 KB
testcase_06 AC 7 ms
16,956 KB
testcase_07 AC 7 ms
17,052 KB
testcase_08 AC 6 ms
16,972 KB
testcase_09 AC 6 ms
16,876 KB
testcase_10 AC 7 ms
16,976 KB
testcase_11 AC 7 ms
16,904 KB
testcase_12 AC 6 ms
16,956 KB
testcase_13 AC 6 ms
16,952 KB
testcase_14 AC 6 ms
16,908 KB
testcase_15 AC 7 ms
16,972 KB
testcase_16 AC 7 ms
17,016 KB
testcase_17 AC 6 ms
16,900 KB
testcase_18 AC 6 ms
16,976 KB
testcase_19 AC 6 ms
17,000 KB
testcase_20 AC 7 ms
17,072 KB
testcase_21 AC 6 ms
16,904 KB
testcase_22 AC 6 ms
16,960 KB
testcase_23 AC 6 ms
16,904 KB
testcase_24 AC 7 ms
16,876 KB
testcase_25 AC 6 ms
17,008 KB
testcase_26 AC 7 ms
16,876 KB
testcase_27 AC 7 ms
17,012 KB
testcase_28 AC 6 ms
17,096 KB
testcase_29 AC 6 ms
16,908 KB
testcase_30 AC 6 ms
17,152 KB
testcase_31 AC 7 ms
16,944 KB
testcase_32 AC 7 ms
17,264 KB
testcase_33 AC 7 ms
17,032 KB
testcase_34 AC 6 ms
16,900 KB
testcase_35 AC 6 ms
16,980 KB
testcase_36 AC 6 ms
16,904 KB
testcase_37 AC 6 ms
17,036 KB
testcase_38 AC 7 ms
17,076 KB
testcase_39 AC 6 ms
16,908 KB
testcase_40 AC 6 ms
16,904 KB
testcase_41 AC 7 ms
16,876 KB
testcase_42 AC 7 ms
17,000 KB
testcase_43 AC 6 ms
17,096 KB
testcase_44 AC 7 ms
16,968 KB
testcase_45 AC 6 ms
16,956 KB
testcase_46 AC 6 ms
16,980 KB
testcase_47 AC 7 ms
16,976 KB
testcase_48 AC 6 ms
16,904 KB
testcase_49 AC 7 ms
17,252 KB
testcase_50 AC 6 ms
16,972 KB
testcase_51 AC 6 ms
17,048 KB
testcase_52 AC 6 ms
16,952 KB
testcase_53 AC 6 ms
16,948 KB
testcase_54 AC 241 ms
16,960 KB
testcase_55 AC 6 ms
16,900 KB
testcase_56 AC 21 ms
17,048 KB
testcase_57 AC 6 ms
17,136 KB
testcase_58 AC 7 ms
16,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
 
ll mod = 1000000007;
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

 
//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[300005],y[300005],z[300005];

char s[500005],t[500005];
 
bool isok;

int main(){
    cin >> h >> w;
    if(w < 0)w *= -1;
    ll add = 1;
    if(w == 0)
    {
        p(0);
        return 0;
    }
    sum = 0;
    if(h > w){
        while(1){
            if(a + add <= w - 1){
                a += add;
                ans += add * add;
            }else{
                ans += (w - 1 - a) * add;
                break;
            }
            if(add < h){
                add++;
            }
            //pe(a);p(ans);
        }
        ans += h;
    }else{
        add = 0;
        while(1){
            add += 1;
            //pe(a);
            if(a + add <= h){
                a += add;
                ans += add * add;
            }else{
                ll h1 = h - a;
                ll h2 = add - h1;
                ll unit = (h1 + h2) * add - h2;
                while(1){
                    //pe(a);
                    if(a + h1 + h2 <= w - 1){
                        sum += unit;
                        a += h1 + h2;
                    }else{
                        break;
                    }
                }
                if(a + h1 <= w - 1 && a + h1 + h2 > w - 1){
                    ans += h1 * add;
                    ans += (w - 1 - h1 - a) * (add - 1);
                }else{
                    ans += (w - 1 - a) * add;
                }
                ans += sum;
                ans += h;
                break;
            }
        }
    }

    p(ans);
    return 0;
}
0