Submission #1316143
Source Code Expand
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a)
#define vlb(a,k) (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ret return
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
///////////////////////////////////////////////////////////////////////////
int main(){
ll x,y;
cin >> x >> y;
ll cnt = 0;
while(x != y){
if(x < y){
if(0 <= x){
cnt += y-x;
x = y;
}else if( 0 <= y){
if(abs(x) < abs(y)){
x = -x;
cnt++;
}else{
cnt += abs(x)-abs(y);
x = -y;
}
}else{
cnt += abs(x)-abs(y);
x = y;
}
}else{
if(x < 0){
x = -x;
cnt++;
}else{
if(abs(x) < abs(y)){
cnt += abs(y)-abs(x) + 1;
x = y;
}else{
cnt++;
x = -x;
}
}
}
}
cout << cnt << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Simple Calculator |
User |
hirata0517masato |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2137 Byte |
Status |
TLE |
Exec Time |
2103 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
1_00.txt |
TLE |
2103 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
1 ms |
256 KB |
1_03.txt |
AC |
1 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
TLE |
2103 ms |
256 KB |
1_06.txt |
AC |
1 ms |
256 KB |
1_07.txt |
AC |
1 ms |
256 KB |
1_08.txt |
AC |
1 ms |
256 KB |
1_09.txt |
TLE |
2103 ms |
256 KB |
1_10.txt |
AC |
1 ms |
256 KB |