Submission #50897

# Submission time Handle Problem Language Result Execution time Memory
50897 2018-06-14T10:36:49 Z tmwilliamlin168 Board (CEOI13_board) C++14
70 / 100
6 ms 3400 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxD=1000, bs=62, mxBC=mxD/bs+1;
int sa, sb, ans=2*mxD, a1=0;
ll bva[mxBC], bvb[mxBC];

inline void rd(ll *bv, int &s) {
	bv[0]=1LL<<(bs-1);
	s=1;
	string ms;
	cin >> ms;
	for(char c : ms) {
		if(c=='1') {
			bv[s/bs]&=~(1LL<<(bs-1-s%bs));
			++s;
		} else if(c=='2') {
			bv[s/bs]|=1LL<<(bs-1-s%bs);
			++s;
		} else if(c=='L') {
			bv[(s-1)/bs]-=1LL<<(bs-1-(s-1)%bs);
			for(int i=(s-1)/bs; bv[i]<0; --i) {
				bv[i]+=1LL<<bs;
				--bv[i-1];
			}
		} else if(c=='R') {
			bv[(s-1)/bs]+=1LL<<(bs-1-(s-1)%bs);
			for(int i=(s-1)/bs; bv[i]>=1LL<<bs; --i) {
				bv[i]-=1LL<<bs;
				++bv[i-1];
			}
		} else
			--s;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	rd(bva, sa);
	rd(bvb, sb);
//	cout << bva[0] << " " << bvb[0] << endl;
	for(int i=0; i<min(sa, sb)&&abs(a1)<=ans; ++i) {
		a1=2*a1+(bva[i/bs]>>(bs-1-i%bs)&1)-(bvb[i/bs]>>(bs-1-i%bs)&1);
//		cout << i << " " << a1 << endl;
		ans=min(abs(a1)+sa-i+sb-i-2, ans);
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 788 KB Output is correct
2 Correct 3 ms 788 KB Output is correct
3 Correct 5 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1128 KB Output is correct
2 Correct 3 ms 1128 KB Output is correct
3 Correct 3 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1612 KB Output is correct
3 Correct 4 ms 1728 KB Output is correct
4 Correct 2 ms 1728 KB Output is correct
5 Correct 3 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1728 KB Output is correct
2 Correct 2 ms 1728 KB Output is correct
3 Correct 2 ms 1728 KB Output is correct
4 Correct 2 ms 1728 KB Output is correct
5 Correct 2 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1736 KB Output is correct
2 Correct 2 ms 1736 KB Output is correct
3 Correct 3 ms 1736 KB Output is correct
4 Correct 3 ms 1736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1772 KB Output is correct
2 Correct 6 ms 2072 KB Output is correct
3 Correct 4 ms 2128 KB Output is correct
4 Correct 2 ms 2128 KB Output is correct
5 Correct 2 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 3088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 3400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -