QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400013#6750. Calculateericmegalovania#WA 1ms3836kbC++205.9kb2024-04-26 21:05:172024-04-26 21:05:17

Judging History

你现在查看的是最新测评结果

  • [2024-04-26 21:05:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-04-26 21:05:17]
  • 提交

answer

#include<bits/stdc++.h>//傻逼高精度,大模拟,之后再写
using namespace std;

#define ONLINE
#ifndef ONLINE
#define debug(...) fprintf(stderr,##__VA_ARGS__)
#else
#define debug(...) ;
#endif

using LL=long long;
using PII=pair<int,int>;

template<typename T>
inline T READ(){
	T x=0; bool f=0; char c=getchar();
	while(c<'0' || c>'9') f|=(c=='-'),c=getchar();
	while(c>='0' && c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
inline int read(){return READ<int>();}
inline LL readLL(){return READ<LL>();}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

//BigIntTiny template from https://github.com/Baobaobear/MiniBigInteger/blob/main/bigint_tiny.h
struct BigIntTiny {
	int sign;
	std::vector<int> v;
	
	BigIntTiny() : sign(1) {}
	BigIntTiny(const std::string &s) { *this = s; }
	BigIntTiny(int v) {
		char buf[21];
		sprintf(buf, "%d", v);
		*this = buf;
	}
	void zip(int unzip) {
		if (unzip == 0) {
			for (int i = 0; i < (int)v.size(); i++)
				v[i] = get_pos(i * 4) + get_pos(i * 4 + 1) * 10 + get_pos(i * 4 + 2) * 100 + get_pos(i * 4 + 3) * 1000;
		} else
			for (int i = (v.resize(v.size() * 4), (int)v.size() - 1), a; i >= 0; i--)
				a = (i % 4 >= 2) ? v[i / 4] / 100 : v[i / 4] % 100, v[i] = (i & 1) ? a / 10 : a % 10;
		setsign(1, 1);
	}
	int get_pos(unsigned pos) const { return pos >= v.size() ? 0 : v[pos]; }
	BigIntTiny &setsign(int newsign, int rev) {
		for (int i = (int)v.size() - 1; i > 0 && v[i] == 0; i--)
			v.erase(v.begin() + i);
		sign = (v.size() == 0 || (v.size() == 1 && v[0] == 0)) ? 1 : (rev ? newsign * sign : newsign);
		return *this;
	}
	std::string to_str() const {
		BigIntTiny b = *this;
		std::string s;
		for (int i = (b.zip(1), 0); i < (int)b.v.size(); ++i)
			s += char(*(b.v.rbegin() + i) + '0');
		return (sign < 0 ? "-" : "") + (s.empty() ? std::string("0") : s);
	}
	bool absless(const BigIntTiny &b) const {
		if (v.size() != b.v.size()) return v.size() < b.v.size();
		for (int i = (int)v.size() - 1; i >= 0; i--)
			if (v[i] != b.v[i]) return v[i] < b.v[i];
		return false;
	}
	BigIntTiny operator-() const {
		BigIntTiny c = *this;
		c.sign = (v.size() > 1 || v[0]) ? -c.sign : 1;
		return c;
	}
	BigIntTiny &operator=(const std::string &s) {
		if (s[0] == '-')
			*this = s.substr(1);
		else {
			for (int i = (v.clear(), 0); i < (int)s.size(); ++i)
				v.push_back(*(s.rbegin() + i) - '0');
			zip(0);
		}
		return setsign(s[0] == '-' ? -1 : 1, sign = 1);
	}
	bool operator<(const BigIntTiny &b) const {
		return sign != b.sign ? sign < b.sign : (sign == 1 ? absless(b) : b.absless(*this));
	}
	bool operator==(const BigIntTiny &b) const { return v == b.v && sign == b.sign; }
	BigIntTiny &operator+=(const BigIntTiny &b) {
		if (sign != b.sign) return *this = (*this) - -b;
		v.resize(std::max(v.size(), b.v.size()) + 1);
		for (int i = 0, carry = 0; i < (int)b.v.size() || carry; i++) {
			carry += v[i] + b.get_pos(i);
			v[i] = carry % 10000, carry /= 10000;
		}
		return setsign(sign, 0);
	}
	BigIntTiny operator+(const BigIntTiny &b) const {
		BigIntTiny c = *this;
		return c += b;
	}
	void add_mul(const BigIntTiny &b, int mul) {
		v.resize(std::max(v.size(), b.v.size()) + 2);
		for (int i = 0, carry = 0; i < (int)b.v.size() || carry; i++) {
			carry += v[i] + b.get_pos(i) * mul;
			v[i] = carry % 10000, carry /= 10000;
		}
	}
	BigIntTiny operator-(const BigIntTiny &b) const {
		if (b.v.empty() || b.v.size() == 1 && b.v[0] == 0) return *this;
		if (sign != b.sign) return (*this) + -b;
		if (absless(b)) return -(b - *this);
		BigIntTiny c;
		for (int i = 0, borrow = 0; i < (int)v.size(); i++) {
			borrow += v[i] - b.get_pos(i);
			c.v.push_back(borrow);
			c.v.back() -= 10000 * (borrow >>= 31);
		}
		return c.setsign(sign, 0);
	}
	BigIntTiny operator*(const BigIntTiny &b) const {
		if (b < *this) return b * *this;
		BigIntTiny c, d = b;
		for (int i = 0; i < (int)v.size(); i++, d.v.insert(d.v.begin(), 0))
			c.add_mul(d, v[i]);
		return c.setsign(sign * b.sign, 0);
	}
	BigIntTiny operator/(const BigIntTiny &b) const {
		BigIntTiny c, d;
		BigIntTiny e=b;
		e.sign=1;
		
		d.v.resize(v.size());
		double db = 1.0 / (b.v.back() + (b.get_pos((unsigned)b.v.size() - 2) / 1e4) +
			(b.get_pos((unsigned)b.v.size() - 3) + 1) / 1e8);
		for (int i = (int)v.size() - 1; i >= 0; i--) {
			c.v.insert(c.v.begin(), v[i]);
			int m = (int)((c.get_pos((int)e.v.size()) * 10000 + c.get_pos((int)e.v.size() - 1)) * db);
			c = c - e * m, c.setsign(c.sign, 0), d.v[i] += m;
			while (!(c < e))
				c = c - e, d.v[i] += 1;
		}
		return d.setsign(sign * b.sign, 0);
	}
	BigIntTiny operator%(const BigIntTiny &b) const { return *this - *this / b * b; }
	bool operator>(const BigIntTiny &b) const { return b < *this; }
	bool operator<=(const BigIntTiny &b) const { return !(b < *this); }
	bool operator>=(const BigIntTiny &b) const { return !(*this < b); }
	bool operator!=(const BigIntTiny &b) const { return !(*this == b); }
};

BigIntTiny ans=0ll,x;
int main(){
	ios::sync_with_stdio(false);
	string s,num=""; cin>>s;
	vector<int>op{0};
	bool flag=0;
	for(char c:s){
		if(c>='0' && c<='9'){
			num+=c;
		}
		else if(c=='?'){
			num+=(flag?"0":"9");
		}
		else{
			if(num.size()){
				debug("num=%s\n",num.c_str());
				x=num;
				if(flag) ans=ans-x;
				else ans=ans+x;
				num="";
			}
			if(c=='('){
				op.push_back(0);
			}
			else if(c==')'){
				op.pop_back();
			}
			else if(c=='+'){
				if(op.back()){
					op.back()=0;
					flag^=1;
				}
			}
			else if(c=='-'){
				if(!op.back()){
					op.back()=1;
					flag^=1;
				}
			}
		}
	}
	if(num.size()){
		debug("num=%s\n",num.c_str());
		x=num;
		if(flag) ans=ans-x;
		else ans=ans+x;
	}
	cout<<ans.to_str();
	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3836kb

input:

?+?

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

(?+9)-(?+1)

output:

17

result:

ok 1 number(s): "17"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3836kb

input:

((9)-(((8)-(2))+(((1+(1))-(1+((2)+2+2)))+(5)+4))+(((7)-((9)+3))-((8)-(0-(2))+0))+((6)-(6+(((4)-(9))-(8-((9)+(1))+(0)))+(2-((9)+7))-(1)))-((((7)+(1))-((3)+(3)))-((2)-((6)-((3)-(8)))))+(2+0-((6)-(1))))-((((3)-(((0)+((4)-(9))+((6+8)+4)+(5)-(4-(3)-(8)))-((8)-(2))))+(((2)-(4))+(6)-(2))+(6-(1))-((2+9)-(3+...

output:

105

result:

wrong answer 1st numbers differ - expected: '-63', found: '105'