Submission #00115
ソースコード
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 | #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int x, y; int ans = 0; for ( int i = 0; i < n; i++ ) { cin>>x>>y; ans = 0; while ( x != 0 || y != 0 ) { // cout<<ans<<" "; if ( x == 0 || y == 0 ) { ans += abs ( x + y ); break ; } else if ( x > 0 && y < 0 ) { x--; y++; ans++; } else if ( x < 0 && y > 0 ) { x++; y--; ans++; } else { if ( x != 0 ) { if ( x < 0 ) { x++; } else { x--; } } ans++; } } cout<<ans<< "\n" ; } } |
ステータス
項目 | データ |
---|---|
問題 | 0007 - ハチの巣距離 |
ユーザー名 | ei2437 |
投稿日時 | 2025-03-28 12:36:24 |
言語 | C++ |
状態 | Accepted |
得点 | 30 |
ソースコード長 | 746 Byte |
最大実行時間 | 25 ms |
最大メモリ使用量 | 544 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 30 / 30 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
C1 | AC | 25 ms | 476 KB |
1
|
C2 | AC | 23 ms | 444 KB |
1
|
C3 | AC | 21 ms | 544 KB |
1
|
C4 | AC | 25 ms | 512 KB |
1
|