結果

問題 No.48 ロボットの操縦
ユーザー kpinkcat
提出日時 2023-08-04 13:49:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 104,140 KB
最終ジャッジ日時 2025-02-15 21:55:36
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:25: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   17 |         if (!(y%l)) ans += y/l;
      |                     ~~~~^~~~~~
main.cpp:14:18: note: ‘ans’ was declared here
   14 |     int x, y, l, ans;
      |                  ^~~

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    int x, y, l, ans;
    cin >> x >> y >> l;
    if (y >= 0){
        if (!(y%l)) ans += y/l;
        else ans += (y/l + 1);
    } else {
        if (y%l) ans += (-y/l + 1);
        else ans += (-y/l + 2);
    }
    if (abs(x) || abs(x)%l) ans += (abs(x)/l + 1);
    else if (abs(x)) ans += (abs(x/l) + 2);
    else ans++;

    cout << ans << endl;
}
0