QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222602#6129. Magic Multiplicationucup-team1001Compile Error//C++202.2kb2023-10-21 17:46:022023-10-21 17:46:02

Judging History

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

  • [2023-10-21 17:46:02]
  • 评测
  • [2023-10-21 17:46:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define irep(i,l,r) for(int i = (l); (i) <= (r); ++ (i))
#define ll long long
inline ll read(){
	ll s = 0;
	bool w = 0;
	char ch = getchar();
	while(! isdigit(ch)){
		if(ch == '-')w = 1;
		ch = getchar();
	}
	while(isdigit(ch)){
		s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	}
	return w ? -s : s;
}

string s;
int len;
int n,m;
vector<int>A,B;
vector<int>AA,BB;
void work(){
	if(AA.size())return;
	A.resize(n);
	string opt[10];
	int optlen[10];
	for(int c = 0; c < 10; ++ c){
		for(int i = 0; i < m; ++ i){
			int val = c * B[i];
			if(val < 10)opt[c] += val + '0';
			else opt[c] += (val / 10) + '0', opt[c] += (val % 10) + '0';
		}
		optlen[c] = opt[c].length();
	}

	int match = 0, pos = 0, ok = 0;
	
	for(int i = 0; i < n; ++ i){
		int pas = 0;
		irep(ch, 0, 9){
			int fl = 0;
			if(pos + optlen[ch] > len)continue;
			if(i == 0 && ch == 0)continue;
			for(int p = 0; p < optlen[ch]; ++ p){
				if(opt[ch][p] != s[pos + p]){
					fl = 1;
					break;
				}
			}
			if(fl == 0){
				pos = optlen[ch] + pos;
				A[i] = ch;
				fl = 1, pas = 1;
				break;
			}
		}
		if(i == n - 1 && pos != len)return;
		if(pas == 0)return;
	}
	if(AA.size() == 0){
		AA = A;
		BB = B;
	}
	
}
void dfs(int x, int a0, int cur){
	if(A.size())return;
	if(cur >= len)return;
	if(x == m){
		if(B[0])work();
		return;
	}

	int op1 = s[cur] - '0', op2 = (s[cur] - '0') * 10 + s[cur + 1] - '0';
	if(op1 % a0 == 0){
		B[x] = op1 / a0;
		dfs(x + 1, a0, cur + 1);
	}
	if(op2 % a0 == 0 && op2 / a0 < 10 && op2 != 0){
		B[x] = op2 / a0;
		dfs(x + 1, a0, cur + 2);
	}
}

void solve(){
	n = read(), m = read();
	A.resize(n);
	B.resize(m);
	AA.clear();
	BB.clear();
	cin >> s;
	len = s.length();
	if(1ll * n * m > s.length()){
		puts("Impossible");
		return;
	}
	if(2ll *n * m < s.length){
		puts("Impossible");
		return;		
	}
	A.push_back(0);
	for(int a0 = 1; a0 < 10; ++ a0){
		A[0] = a0;
		B.resize(m);
		dfs(0, a0, 0);
	}
	if(AA.size() == 0){
		puts("Impossible");
		return;
	}else{
		for(int x : AA)printf("%d", x);
		putchar(' ');
		for(int x : BB)printf("%d",x);
		putchar('\n');
	}
}

int main(){
	int T = read();
	while(T --){
		solve();
	}
}

Details

answer.code: In function ‘void solve()’:
answer.code:99:27: error: invalid use of member function ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::length() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]’ (did you forget the ‘()’ ?)
   99 |         if(2ll *n * m < s.length){
      |                         ~~^~~~~~
      |                                 ()