| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 340053 | AlperenT | Slon (COCI15_slon) | C++17 | 9 ms | 1132 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long p, m, numx, numa;
string str, postfix;
stack<char> poststack;
struct operand{
	long long x, a;
	operand operator+(operand y){
		struct operand temp;
		temp.x = x + y.x;
		temp.a = a + y.a;
		return temp;
	}
	operand operator-(operand y){
		struct operand temp;
		temp.x = x - y.x;
		temp.a = a - y.a;
		return temp;
	}
	operand operator*(operand y){
		struct operand temp;
		
		if(x == 0){
			temp.x = a * y.x;
			temp.a = a * y.a;
		}
		else{
			temp.x = y.a * x;
			temp.a = y.a * a;
		}
		return temp;
	}
};
stack<operand> operands;
int main(){    
	cin >> str >> p >> m;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == 'x'){
			postfix += str[i];
			postfix += " ";
		}
		else if(isdigit(str[i])){
			long long val = 0;
			while(i < str.size() && isdigit(str[i])){
				val = (val * 10) + (str[i] - '0');
				i++;
			}
			postfix += to_string(val);
			postfix += " ";
			i--;
		}
		else{
			if(str[i] == '+' || str[i] == '-'){
				while(!poststack.empty() && poststack.top() != '(' && poststack.top() != ')'){
					postfix += poststack.top();
					postfix += " ";
					poststack.pop();
				}
				poststack.push(str[i]);
			}
			else if(str[i] == '*'){
				while(!poststack.empty() && poststack.top() == '*' && poststack.top() != '(' && poststack.top() != ')'){
					postfix += poststack.top();
					postfix += " ";
					poststack.pop();
				}
				poststack.push(str[i]);
			}
			else if(str[i] == '('){
				poststack.push(str[i]);
			}
			else if(str[i] == ')'){
				while(!poststack.empty() && poststack.top() != '('){
					postfix += poststack.top();
					postfix += " ";
					poststack.pop();
				}
				if(poststack.top() == '('){
					poststack.pop();
				}
			}
		}
	}
	while(!poststack.empty()){
		postfix += poststack.top();
		postfix += " ";
		poststack.pop();
	}
	for(int i = 0; i < postfix.size(); i++){
		if(isdigit(postfix[i])){
			long long val = 0;
			while(i < postfix.size() && isdigit(postfix[i])){
				val = (val * 10) + (postfix[i] - '0');
				i++;
			}
			struct operand temp;
			temp.x = 0;
			temp.a = val;
			operands.push(temp);
		}
		else if(postfix[i] == 'x'){
			struct operand temp;
			temp.x = 1;
			temp.a = 0;
			operands.push(temp);
		}
		else if(postfix[i] == '+' || postfix[i] == '-' || postfix[i] == '*'){
			struct operand tempa, tempb;
			tempb = operands.top();
			operands.pop();
			tempa = operands.top();
			operands.pop();
			if(postfix[i] == '+'){
				operands.push(tempa + tempb);
			}
			else if(postfix[i] == '-'){
				operands.push(tempa - tempb);
			}
			else{
				operands.push(tempa * tempb);
			}
		}
	}
	numx = operands.top().x % m;
	numa = operands.top().a % m;
	for(long long i = 0; i <= m; i++){
		if((numx * i + numa) % m == p){
			cout << i;
			return 0;
		}
	}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
