답안 #100265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100265 2019-03-10T07:13:51 Z ami Lun (COCI19_lun) C++14
50 / 50
3 ms 384 KB
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

bool valid(string s) {
	reverse(s.begin(),s.end());
	int sum=0;
	rep(i,1,sz(s)) {
		int c=s[i]-'0';
		if (i%2==1) {
			c*=2;
			sum+=c%10 + c/10;
		} else {
			sum+=c;
		}
	}
	return (sum*9)%10 == int(s[0]-'0');
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int n;
	string s;
	cin>>n>>s;
	int x=int(s.find('x'));
	rep(i,0,10) {
		s[x]=char('0'+i);
		if (valid(s)) {
			cout<<i<<"\n";
			return 0;
		}
	}

	assert(false);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 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 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct