QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#222311#5. 在线 O(1) 逆元ucup-team1001Compile Error//C++202.2kb2023-10-21 16:41:022024-11-05 21:53:59

Judging History

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

  • [2024-11-05 21:53:59]
  • 管理员手动重测本题所有提交记录
  • [2023-10-21 16:41:03]
  • 评测
  • [2023-10-21 16:41: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<vector<int>>AA,BB;
void work(){
	
	//cout << A[0] << endl ;
	//irep(i, 0, m -1)cout << B[i];
	//cout << endl;
	
	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();
//		cout << opt[c] << endl;
	}

	int match = 0, pos = 0, ok = 0;
	
	for(int i = 0; i < n; ++ i){
		irep(ch, 0, 9){
			if(i == 0 && ch == 0)continue;
			bool fl = 0;
			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;
			}
			else{
				ok = 1;
			}
		}
	}
	if(ok == 0){
		AA.push_back(A);
		BB.push_back(B);
	}
	
}
void dfs(int x, int a0, int cur){
	
	if(x == m){
		if(B[0])work();
		return;
	}

	int op1 = s[cur] - '0', op2 = (s[cur] - '0') * 10 + s[cur + 1] - '0';
//	cerr << x << ' ' << A[0] << ' ';
	irep(i, 0, x - 1) cerr << B[i];
//	cerr << endl;
	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(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 : A)printf("%d", x);
		putchar(' ');
		for(int x : B)printf("%d",x);
		putchar('\n');
	}
}

int main(){
	int T = read();
	while(T --){
		solve();
		//cout << endl;
	}
}

详细

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccdzowSh.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6WOh1f.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc6WOh1f.o: in function `main':
implementer.cpp:(.text.startup+0x12b): undefined reference to `init(int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1d0): undefined reference to `inv(int)'
collect2: error: ld returned 1 exit status