# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100318 |
2019-03-10T11:39:02 Z |
ozneroL |
Lun (COCI19_lun) |
C++14 |
|
3 ms |
384 KB |
#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;
}
Compilation message
lun.cpp: In function 'int main()':
lun.cpp:79:9: warning: unused variable 'N' [-Wunused-variable]
int N = II();
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |