Skip to content

Instantly share code, notes, and snippets.

@nukopy
Created January 5, 2019 12:56
Show Gist options
  • Save nukopy/3720619c5202b941aafa3787ef584c04 to your computer and use it in GitHub Desktop.
Save nukopy/3720619c5202b941aafa3787ef584c04 to your computer and use it in GitHub Desktop.
ABC088: C - Takahashi's Information
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator> // std::back_inserter()
#include <set>
#include <map>
#include <algorithm> // std::copy()
#include <functional> // std::greater<T>()
#include <utility> // std::swap()
#include <numeric> // accumulate(ALL(vec), 0) 0 は初期値
#include <bitset> // static_cast<std::bitset<8>>
#include <sstream> // std::stringstream
#include <cmath>
#include <climits> // INT_MIN
#include <cctype> // std::isdigit()
#include <iomanip> // std::setprecision()
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++) // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++) // 1 ~ n
#define MIN(vec) min_element(ALL((vec))) // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0) // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2)) // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;
const int MOD = 1000000007; // 1 000 000 007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
size_t len = 3;
vector< vector<int> > vec(len, vector<int>(len)); // (N, M) array 0で初期化
int max_num = -1;
REP(i, len) {
REP(j, len) {
cin >> vec[i][j];
}
}
// calculation
int max_r0 = *MAX(vec[0]), max_r1 = *MAX(vec[1]), max_r2 = *MAX(vec[2]);
int a1, a2, b0, b1, b2;
vector<int> a2_candidate(3), a3_candidate(3);
int a2_can, a3_can, num_a2, num_a3;
for (int a0 = 0; a0 <= max_r0; ++a0) {
// b0
b0 = vec[0][0] - a0;
b1 = vec[0][1] - a0;
b2 = vec[0][2] - a0;
// a2 candidate
a2_candidate[0] = vec[1][0] - b0;
a2_candidate[1] = vec[1][1] - b1;
a2_candidate[2] = vec[1][2] - b2;
// a3 candidate
a3_candidate[0] = vec[2][0] - b0;
a3_candidate[1] = vec[2][1] - b1;
a3_candidate[2] = vec[2][2] - b2;
a2_can = a2_candidate[0];
a3_can = a3_candidate[0];
num_a2 = 0;
num_a3 = 0;
REP(i, 3) {
if (a2_candidate[i] < 0 || a3_candidate[i] < 0) break;
if (a2_can == a2_candidate[i]) num_a2++;
if (a3_can == a3_candidate[i]) num_a3++;
}
if (num_a2 == 3 && num_a3 == 3) {
cout << "Yes" << "\n";
return 0;
}
}
cout << "No" << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment