답안 #339961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339961 2020-12-26T12:27:05 Z Nimbostratus Slon (COCI15_slon) C++17
0 / 120
24 ms 876 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;
}

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));
			}
			op.pop();
		}
		else
		{
			while(!op.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;
	int cx = extract_x(A);
	int cc = extract_c(A);
	//cout << cx << " " << cc << endl;
	for(int i=0;i<=2*M+1;i++)
	{
		if((cx*i + cc)% M == P)
		{
			cout << i << endl;
			return 0;
		}
	}
}

Compilation message

slon.cpp: In function 'long long int eval(std::string)':
slon.cpp:38: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]
   38 |  for(int i=0;i<sz(a);i++)
      |               ^
slon.cpp:44: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]
   44 |    while(i < sz(a) and isdigit(a[i]))
      |            ^
slon.cpp: In function 'long long int extract_c(std::string&)':
slon.cpp:98: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]
   98 |  for(int i=0;i<sz(a);i++)
      |               ^
slon.cpp: In function 'long long int extract_x(std::string&)':
slon.cpp:108: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]
  108 |  for(int i=0;i<sz(a);i++)
      |               ^
slon.cpp: In function 'long long int applyOp(long long int, long long int, char)':
slon.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 364 KB Output isn't correct
2 Incorrect 19 ms 876 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 24 ms 364 KB Output isn't correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 16 ms 492 KB Output isn't correct
9 Incorrect 4 ms 620 KB Output isn't correct
10 Incorrect 6 ms 748 KB Output isn't correct