QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374369 | #3716. Simple Arithmetic | ucup-team1251 | AC ✓ | 3ms | 3552kb | C++17 | 3.1kb | 2024-04-02 13:53:46 | 2024-04-02 13:53:47 |
Judging History
answer
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#define ll unsigned long long
using namespace std;
const int mod = 1e9 + 7;
__int128 read()
{
__int128 x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
f = -1, ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
void print(__int128 x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
string s1, s2;
while (cin >> s1 >> s2)
{
if (s1 == "-9223372036854775808" || s2 == "-9223372036854775808")
{
ll a = 0, b = 0;
if (s1 == "-9223372036854775808" && s2 == "-9223372036854775808")
{
cout << "1";
}
else if (s1 == "-9223372036854775808")
{
ll c = 9223372036854775807;
c++;
// cout << c << endl;
if (s2[0] == '-')
{
for (int i = 1; i < s2.size(); i++)
{
b *= 10;
b += s2[i] - '0';
}
cout << c / b;
}
else
{
for (int i = 0; i < s2.size(); i++)
{
b *= 10;
b += s2[i] - '0';
}
cout << "-" << (c / b - (c % b != 0));
}
}
else
{
if (s1[0] == '-' || s1[0] == '0')
{
cout << "0";
}
else
{
cout << "-1";
}
}
}
else
{
long long a = 0, b = 0;
// a = read() ; b = read();
if (s2[0] == '-')
{
for (int i = 1; i < s2.size(); i++)
{
b *= 10;
b += s2[i] - '0';
}
b *= -1;
}
else
{
for (int i = 0; i < s2.size(); i++)
{
b *= 10;
b += s2[i] - '0';
}
}
if (s1[0] == '-')
{
for (int i = 1; i < s1.size(); i++)
{
a *= 10;
a += s1[i] - '0';
}
a *= -1;
}
else
{
for (int i = 0; i < s1.size(); i++)
{
a *= 10;
a += s1[i] - '0';
}
}
if ((a < 0 && b < 0) || (a > 0 && b > 0))
{
ll c = a / b;
cout << c;
}
else
{
cout << a / b - (a % b != 0);
}
}
cout << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3552kb
input:
3 2 3 -2 -9223372036854775808 1 -9223372036854775808 -1 9223372036854775807 1 9223372036854775807 -1 -9223372036854775808 2 -9223372036854775808 -2 9223372036854775807 2 9223372036854775807 -2 -2076046199237518199 8895005889588087898 -3939164353449408 -1673591601308294572 236330652387008908 24746725...
output:
1 -2 -9223372036854775808 9223372036854775808 9223372036854775807 -9223372036854775807 -4611686018427387904 4611686018427387904 4611686018427387903 -4611686018427387904 -1 0 0 -1 -1 2 -2 -1 0 -2 1 0 0 -2 1 0 -37 0 0 3 -1 8 -1 8 -1 -1 -2 0 0 2 8 -1 0 -1 -2 -1 -5 -7 -1 -2 -3 -1 1 0 -11 -1 2 -1 11 8 0 ...
result:
ok 9875 tokens