# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1038724 |
2024-07-30T06:56:53 Z |
vjudge1 |
Slon (COCI15_slon) |
C++17 |
|
4 ms |
1372 KB |
#include<bits/stdc++.h>
using namespace std;
int solution(string s, int M)
{
// apply_product;
string pf;
int num = 0;
for(int i = 0; i < s.size(); i++)
{
// cerr << "i : " << i << endl;
if('0' <= s[i] && s[i] <= '9')
num = (num * 10ll % M + s[i] - '0') % M;
else if(s[i] != '*')
pf += to_string(num), num = 0, pf += s[i];
else
{
int num2 = 0;
bool b = true;
for(int j = i + 1; j < s.size(); j++)
{
if(s[j] < '0' || s[j] > '9') {
i = j - 1;
b = false;
break;
}
num2 = (num2 * 10ll % M + s[j] - '0') % M;
}
// cerr << num << ' ' << num2 << endl;
// cerr << num * num2 % M << endl;
num = num * num2 % M;
if(b) break;
}
}
// cerr << num << endl;
pf += to_string(num);
pf = "+" + pf;
// cerr << pf << endl;
int ans = 0;
for(int i = 0; i < pf.size(); i ++)
{
int c = (pf[i] == '+') ? 1 : -1;
int num2 = 0;
bool b = true;
for(int j = i + 1; j < pf.size(); j++)
{
if(pf[j] < '0' || pf[j] > '9') {
i = j - 1;
b = false;
break;
}
num2 = (num2 * 10ll % M + pf[j] - '0') % M;
}
// cerr << num2 << endl;
num2 *= c;
ans = ((ans + num2) % M + M) % M;
if(b) break;
}
// cerr << ans << endl;
return ans;
}
int solve(string s, int x, int M)
{
string problem = '(' + s + ')';
vector<int> last;
vector<string> exp = {""};
for(char i : problem)
{
if(i == '(')
exp.push_back("");
else if(i == ')')
{
// cerr << "exp: " << exp.back() << endl;
int val = solution(exp.back(), M);
exp.pop_back();
exp.back() += to_string(val);
}
else if(i == 'x')
exp.back() += to_string(x);
else
exp.back() += i;
}
return stoi(exp.back());
}
int main()
{
string s;
int P, M;
cin >> s >> P >> M;
int f = solve(s, 0, M), sec = solve(s, 1, M);
int d = sec - f;
// cerr << f << ' ' << sec << endl;
for(int i = 0; i < M; i++)
{
f %= M, f = (f + M) % M;
if(f == P)
{
cout << i << endl;
return 0;
}
f += d;
}
cout << "I was just kidding\n";
return 0;
}
Compilation message
slon.cpp: In function 'int solution(std::string, int)':
slon.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i = 0; i < s.size(); i++)
| ~~^~~~~~~~~~
slon.cpp:22:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int j = i + 1; j < s.size(); j++)
| ~~^~~~~~~~~~
slon.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < pf.size(); i ++)
| ~~^~~~~~~~~~~
slon.cpp:47:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int j = i + 1; j < pf.size(); j++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
2 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
9 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
10 |
Runtime error |
3 ms |
1212 KB |
Execution killed with signal 11 |