Submission #319149

# Submission time Handle Problem Language Result Execution time Memory
319149 2020-11-04T09:11:18 Z sofapuden Odd-even (IZhO11_oddeven) C++14
0 / 100
1022 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

string add(string a, string b){
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	while(a.size() < b.size()){
		a+='0';
	}
	while(b.size() < a.size()){
		b+='0';
	}
	int last = 0;
	for(int i = 0; i < (int)a.size(); ++i){
		int cur = a[i]+b[i]-2*'0' + last;
		last = cur/10;
		c+=(char)('0'+cur%10);
	}
	if(last){
		c+=(char)('0'+last);
	}
	reverse(c.begin(),c.end());
	return c;
}
string subs(string a, string b){
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	while(b.size() < a.size()){
		b+='0';
	}
	int last = 0;
	for(int i = 0; i < (int)a.size(); ++i){
		int cur = a[i]-b[i] + last;
		last = (cur-10)/10;
		c+=(char)('0'+((cur+10)%10));
	}
	while(c.back() == '0')c.pop_back();
	reverse(c.begin(),c.end());
	return c;
}

bool gre(string a, string b){
	if(a.size() > b.size()){
		return true;
	}
	if(b.size() > a.size()){
		return false;
	}
	return a >= b;
}
	

int main(){
	string a; cin >> a;
	string cn = "1";
	string cur = "1";
	while(!gre(cur,a)){
		cn = add(cn,"1");
		cur = add(cur,cn);
	}
	cout << subs(add(a,a),cn);
		
	
			
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Incorrect 1022 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -