# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100318 | ozneroL | Lun (COCI19_lun) | C++14 | 3 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define ERR 1e-9
#if !ONLINE_JUDGE && !EVAL
#define dbg_var(x) cerr << #x << ": " << x << "\n";
#define dbg_iter(x, y) cerr << #x << ": " << print_iterable(x, y) << "\n";
#else
#define dbg_var(x)
#define dbg_iter(x, y)
#endif // ONLINE_JUDGE
template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
bool first = true;
stringstream res;
res << "[ ";
for(; begin_iter != end_iter; ++begin_iter){
if(!first) res << ", ";
first = false;
res << *begin_iter;
}
res << " ]";
return res.str();
}
void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }
int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }
// constraints
#define MAXN 1000000
int sum(int n){
int res = 0;
while(n){
res += n%10;
n /= 10;
}
return res;
}
int lastStep(int sum, int mod){
for(int i=0; i<=9; i++){
if( (i*9+sum) % 10 == mod)
return i;
}
/// value x in the sum
return 0;
}
int findNumber(int xInTheSum){
for(int i=0; i<=9; i++){
if( sum(i*2) == xInTheSum)
return i;
}
return 0;
}
#define sz(s) int(s.size())
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int N = II();
string s;
cin >> s;
if(s[sz(s)-1] == 'x'){
bool toDouble = true; int total_sum = 0;
for(int i=sz(s)-2; i>=0; i--){
if(toDouble) total_sum += sum( (s[i] - '0') * 2);
else total_sum += (s[i] - '0');
toDouble = !toDouble;
}
cout << (total_sum * 9) % 10 << "\n";
}else{
bool toDouble = true, xToDouble = false;
int total_sum = 0;
for(int i=sz(s)-2; i>=0; i--){
if(s[i] == 'x'){
xToDouble = toDouble;
toDouble = !toDouble;
continue;
}
if(toDouble) total_sum += sum( (s[i] - '0')*2);
else total_sum += s[i] - '0';
toDouble = !toDouble;
}
int xInTheSum = lastStep(total_sum*9, s[sz(s)-1] - '0');
if(!xToDouble) cout << xInTheSum << "\n";
else cout << findNumber(xInTheSum) << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |