結果

問題 No.185 和風
ユーザー kichirb3kichirb3
提出日時 2018-02-28 17:08:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 794 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 70,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 11:19:47
合計ジャッジ時間 1,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.185 和風
// https://yukicoder.me/problems/no/185
//
#include <iostream>
#include <vector>
using namespace std;
int solve(vector<pair<int, int>> &equations);


int main() {
    unsigned int N;
    cin >> N;

    vector<pair<int, int>> equations;
    for (auto i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        equations.push_back(make_pair(x, y));
    }

    int ans = solve(equations);
    cout << ans << endl;
}

int solve(vector<pair<int, int>> &equations) {
    int ans = equations[0].second - equations[0].first;
    if (ans <= 0)
        return -1;

    for (auto i = 1; i < equations.size(); i++) {
        int tmp = equations[i].second - equations[i].first;
        if (tmp != ans) {
            ans = -1;
            break;
        }
    }
    return ans;
}
0