結果

問題 No.1120 Strange Teacher
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2020-07-22 22:15:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,473 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 105,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 21:10:44
合計ジャッジ時間 3,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 20 ms
4,376 KB
testcase_13 AC 20 ms
4,380 KB
testcase_14 AC 20 ms
4,380 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 20 ms
4,376 KB
testcase_17 AC 20 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 21 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:88:39: 警告: ‘diff’ may be used uninitialized [-Wmaybe-uninitialized]
   88 |             else cout << diff + ab << '\n';
      |                                       ^~~~
main.cpp:51:23: 備考: ‘diff’ はここで定義されています
   51 |         int bcnt = 0, diff;
      |                       ^~~~

ソースコード

diff #

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    if (a == b) cout << 0 << '\n';
    else {
        int bcnt = 0, diff;
        for (int i = 0; i < n; i++) {
            if (a[i] < b[i]) {
                bcnt++;
                diff = b[i] - a[i];
            }
        }
        if (bcnt > 1) {
            cout << -1 << '\n';
            return 0;
        }
        for (int i = 0; i < n; i++) {
            if (a[i] < b[i]) a[i] = b[i];
            else a[i] -= diff;
        }

        bcnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == b[i]) bcnt++;
        }
        if (bcnt == n) {
            cout << diff << '\n';
            return 0;
        } else if (bcnt != 2) {
            cout << -1 << '\n';
            return 0;
        } else {
            int ab = INF;
            for (int i = 0; i < n; i++) {
                if (a[i] == b[i]) continue;
                if (ab == INF) ab = a[i] - b[i];
                else if (ab != a[i] - b[i]) {
                    cout << -1 << '\n';
                    return 0;
                }
            }
            if (ab < 0 || (ab & 1)) cout << -1 << '\n';
            else cout << diff + ab << '\n';
        }
    }
    return 0;
}
0