# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
339968 |
2020-12-26T13:00:09 Z |
Nimbostratus |
Slon (COCI15_slon) |
C++17 |
|
36 ms |
1036 KB |
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define all(x) (x.begin() , x.end())
#define sz(x) (x.size())
#define fre freopen("in","r",stdin); freopen("out","w",stdout);
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<int> vint;
#define int long long
const int MAXN = 1e5;
int prec(char op)
{
if(op == '+' or op == '-') return 1;
if(op == '*') return 2;
return 0;
}
int applyOp(int val1,int val2,char op)
{
if(op == '+') return val1 + val2;
if(op == '-') return val1 - val2;
if(op == '*') return val1 * val2;
return 0;
}
int eval(string a)
{
stack<char> op;
stack<int> val;
for(int i=0;i<sz(a);i++)
{
if(a[i] == '(') op.push('(');
else if(isdigit(a[i]))
{
int num = 0;
while(i < sz(a) and isdigit(a[i]))
{
num = num*10 + (a[i]-'0');
i++;
}
val.push(num);
i--;
}
else if(a[i] == ')')
{
while(!op.empty() and op.top() != '(')
{
int val2 = val.top();
val.pop();
int val1 = val.top();
val.pop();
char opp = op.top();
op.pop();
val.push(applyOp(val1,val2,opp));
}
if(!op.empty())
op.pop();
}
else
{
while(!op.empty() and !val.empty() and prec(op.top()) >= prec(a[i]))
{
int val2 = val.top();
val.pop();
int val1 = val.top();
val.pop();
char opp = op.top();
op.pop();
val.push(applyOp(val1,val2,opp));
}
op.push(a[i]);
}
}
while(!op.empty())
{
int val2 = val.top();
val.pop();
int val1 = val.top();
val.pop();
char opp = op.top();
op.pop();
val.push(applyOp(val1,val2,opp));
}
return val.top();
}
int extract_c(string b)
{
string a = b;
for(int i=0;i<sz(a);i++)
if(a[i] == 'x')
a[i] = '0';
return eval(a);
}
int extract_x (string b)
{
string a = b;
for(int i=0;i<sz(a);i++)
if(a[i] == 'x')
a[i] = '1';
return eval(a) - extract_c(b);
}
string A;
int M,P;
int32_t main()
{
//fre;
fast_io;
cin >> A >> P >> M;
//cout << A << " " << P << " " << M << endl;
int cx = extract_x(A);
int cc = extract_c(A);
//cout << cx << " " << cc << endl;
for(int i=0;i<=3*M+1;i++)
{
if(((cx*i + cc)+M)%M == P)
{
cout << i;// << endl;
return 0;
}
}
}
Compilation message
slon.cpp: In function 'long long int eval(std::string)':
slon.cpp:39:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<sz(a);i++)
| ^
slon.cpp:45:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while(i < sz(a) and isdigit(a[i]))
| ^
slon.cpp: In function 'long long int extract_c(std::string)':
slon.cpp:100:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i=0;i<sz(a);i++)
| ^
slon.cpp: In function 'long long int extract_x(std::string)':
slon.cpp:110:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i=0;i<sz(a);i++)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
21 ms |
1036 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
13 ms |
364 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
364 KB |
Output isn't correct |
6 |
Incorrect |
36 ms |
364 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
8 |
Incorrect |
23 ms |
492 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
748 KB |
Output isn't correct |
10 |
Incorrect |
7 ms |
876 KB |
Output isn't correct |