QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#343541#8058. Binary vs Ternaryucup-team191#Compile Error//C++231.8kb2024-03-02 18:25:162024-03-02 18:25:17

Judging History

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

  • [2024-03-02 18:25:17]
  • 评测
  • [2024-03-02 18:25:16]
  • 提交

answer

#include <cstdio>
#include <cassert>
#include <iostream>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef pair < int, int > pii;

const char en='\n';

void solve() {
	string A, B;
	cin >> A >> B;
	if((int)A.size() == 1 || (int)B.size() == 1) {
		if(A != B)
			cout << -1 << en;
		else
			cout << 0 << en;
		return;
	}
	vector < pii > sol;
	int k = (int)A.size() - 1;
	int poc = (int)A.size();
	while(A[k] == '0') k--, A.pop_back();
	if(poc != (int)A.size()) {
		if((int)A.size() + 1 != poc)
			sol.PB({(int)A.size() + 1, poc});
		sol.PB({(int)A.size(), (int)A.size() + 1});
		A.PB('1');
	}
	assert(A.back() == '1'); 
	A.pop_back();
	while((int)A.size() != 1) {
		if(A.back() == '0') {
			sol.PB({(int)A.size(), (int)A.size() + 1});
			A.pop_back();
		} else {
			A.pop_back();
			if(A.back() == '0') {
				sol.PB({(int)A.size(), (int)A.size() + 1});
				A.pop_back();
				A.PB('1');
			} else {
				sol.PB({(int)A.size(), (int)A.size() + 1});
				sol.PB({(int)A.size() + 1, (int)A.size() + 3});
			}
		}
	}
	A.PB('1');
	while((int)A.size() < (int)B.size()) {
		sol.PB({(int)A.size() - 1, (int)A.size()});
		sol.PB({(int)A.size() - 1, (int)A.size()});
		sol.PB({(int)A.size(), (int)A.size() + 1});
		A.PB('1');
	} 
	while(A != B) {
		if(A.back() != B.back()) {
			if(A.back() == '0') {
				sol.PB({(int)A.size() - 1, (int)A.size()});
			} else {
				sol.PB({(int)A.size() - 1, (int)A.size()});
				sol.PB({(int)A.size(), (int)A.size() + 1});
			}
		}
		A.pop_back(); B.pop_back();
	}
	cout << (int)sol.size() << en;
	for(auto tmp : sol) cout << tmp.X << " " << tmp.Y << en;
	sol.clear();
}
 

int main() {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	int T; cin >> T;
	for(;T--;) solve();
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:26:9: error: ‘vector’ was not declared in this scope
   26 |         vector < pii > sol;
      |         ^~~~~~
answer.code:5:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    4 | #include <algorithm>
  +++ |+#include <vector>
    5 | 
answer.code:26:22: error: expected primary-expression before ‘>’ token
   26 |         vector < pii > sol;
      |                      ^
answer.code:26:24: error: ‘sol’ was not declared in this scope
   26 |         vector < pii > sol;
      |                        ^~~