Codeforces Round #731 (Div. 3)

A. Shortest Path with Obstacle

#include "bits/stdc++.h"
using namespace std;   
// fast read
const auto fr = [](){
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return 1;
}();
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; };
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
// vars:
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using pii = std::pair<int,int>;
using pil = std::pair<int,ll>;
using pli = std::pair<ll,int>;
using pll = std::pair<ll,ll>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
// consts
ll M = 0;
// ksm (kuai su mi)
ll ksm(ll a,ll p){ll res=1;while(p){if(p&1){res=res*a%M;}a=a*a%M;p>>=1;}return res;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

int main() { 
    fr; 
    int T;
	cin >> T;
	while (T--)
	{ 
		int X1,Y1,X2,Y2,OX,OY;
		cin >> X1 >> Y1 >> X2 >> Y2 >> OX >> OY;
		ll res = 0;  
		res += abs(X2 - X1);
		res += abs(Y2 - Y1);
		if(X1 == X2 && X2 == OX && ((Y1 < OY && OY < Y2) || (Y2 < OY && OY < Y1)))
		{
			res += 2;
		}
		else if(Y1 == Y2 && Y2 == OY &&  ((X1 < OX && OX < X2) || (X2 < OX && OX < X1)))
		{
			res += 2;
		}
		cout << res << endl;
	}
    return 0; 
}

B. Alphabetical Strings

#include "bits/stdc++.h"
using namespace std;   
// fast read
const auto fr = [](){
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return 1;
}();
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; };
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
// vars:
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using pii = std::pair<int,int>;
using pil = std::pair<int,ll>;
using pli = std::pair<ll,int>;
using pll = std::pair<ll,ll>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
// consts
ll M = 0;
// ksm (kuai su mi)
ll ksm(ll a,ll p){ll res=1;while(p){if(p&1){res=res*a%M;}a=a*a%M;p>>=1;}return res;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

int main() { 
    fr; 
    int T;
	cin >> T;
	while (T--)
	{ 
		string s;
		cin >> s;
		int a = -1;
		for(int i = 0; i < s.length(); i++)
		{
			if(s[i] == 'a')
			{
				a = i;
				break;
			}
		}
		if(a == -1)
		{
			cout << "NO" << endl;
			continue;
		}
		int i = a - 1;
		int j = a + 1; 
		int flag = 1;
		int k = 1;
		while (flag)
		{
			flag = 0;
			if(i >= 0 && s[i] == 'a' + k)
			{
				i--; k++; flag = 1;
			}
			else if(j <= s.length() - 1 && s[j] == 'a' + k)
			{
				j++; k++; flag = 1;
			}
		}
		if(i < 0 && j >= s.length())
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
    return 0; 
}

C. Pair Programming

#include "bits/stdc++.h"
using namespace std;   
// fast read
const auto fr = [](){
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return 1;
}();
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; };
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
// vars:
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using pii = std::pair<int,int>;
using pil = std::pair<int,ll>;
using pli = std::pair<ll,int>;
using pll = std::pair<ll,ll>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
// consts
ll M = 0;
// ksm (kuai su mi)
ll ksm(ll a,ll p){ll res=1;while(p){if(p&1){res=res*a%M;}a=a*a%M;p>>=1;}return res;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

int main() { 
    fr; 
    int T;
	cin >> T;
	while (T--)
	{ 
		int K,N,M;
		cin >> K >> N >> M;
		int A[N];
		for(int i = 0; i < N; i++)
			cin >> A[i];
		int B[M];
		for(int i = 0; i < M; i++)
			cin >> B[i];
		int i = 0, j = 0;
		ll max = K;
		int flag = 1;
		vector<int> v;
		while (flag)
		{
			flag = 0;
			while (i < N && A[i] <= max)
			{
				if(A[i] == 0)
					max++;
				v.push_back(A[i++]);
				flag = 1;
			}
			while (j < M && B[j] <= max)
			{
				if(B[j] == 0)
					max++;
				v.push_back(B[j++]);
				flag = 1;
			}
		}
		if(i == N && j == M)
		{
			for(int i = 0; i < v.size(); i++)
				cout << v[i] << " ";
			cout << endl;
		}
		else
		{
			cout << -1 << endl;
		}
		
	}
    return 0; 
}

D. Co-growing Sequence

#include "bits/stdc++.h"
using namespace std;   
// fast read
const auto fr = [](){
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return 1;
}();
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.first << ", " << p.second << ")"; };
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
// vars:
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vvi = std::vector<vi>;
using vvl = std::vector<vl>;
using pii = std::pair<int,int>;
using pil = std::pair<int,ll>;
using pli = std::pair<ll,int>;
using pll = std::pair<ll,ll>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
// consts
ll M = 0;
// ksm (kuai su mi)
ll ksm(ll a,ll p){ll res=1;while(p){if(p&1){res=res*a%M;}a=a*a%M;p>>=1;}return res;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a % b);}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

int main() { 
    fr; 
    int T;
	cin >> T;
	auto build = [&](int x, int y){return x & ~y;};
	while (T--)
	{ 
		int N;
		cin >> N;
		int A[N];
		for(int i = 0; i < N; i++)
			cin >> A[i];
		int B[N]={0};
		for(int i = 1; i < N; i++) 
			B[i] = build(B[i - 1] ^ A[i - 1], A[i]);
		for(int i = 0; i < N; i++)
			cout << B[i] << " ";
		cout << endl;
	}
    return 0; 
}

D的题意是通过下面的图推出来的