| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 339972 | Nimbostratus | Slon (COCI15_slon) | C++17 | 36 ms | 1004 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 == P or ((cx*i + cc))%M == P-M)
		{
			cout << i%M;// << endl;
			return 0;
		}
	}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
