답안 #384266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384266 2021-04-01T04:50:31 Z AdiZer0 Zamjena (COCI18_zamjena) C++17
14 / 70
1000 ms 3948 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)5e4 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;
 
string a[N], b[N];

string make_string(int x) { 
    string res;
    while (x) { 
        res += (char((x % 10) + '0'));
        x /= 10;
    }
    reverse(whole(res));
    return res;
}

int main() { 
    int n; cin >> n;
    set<string> all;
    for (int i = 1; i <= n; ++i) { 
        cin >> a[i];
        if ('a' <= a[i][0] && a[i][0] <= 'z') all.insert(a[i]);
    }
    for (int i = 1; i <= n; ++i) { 
        cin >> b[i];
        if ('a' <= b[i][0] && b[i][0] <= 'z') all.insert(b[i]);
    }
    for (auto to : all) {
        bool f = 0;
        for (int x = 1; x <= 1000; ++x) { 
            bool good = 1;
            for (int i = 1; i <= n; ++i) { 
                string cur1 = a[i], cur2 = b[i];
                if (cur1 == to || cur2 == to) { 
                    if (cur1 == to) cur1 = make_string(x);
                    if (cur2 == to) cur2 = make_string(x);
                    if (('a' <= cur1[0] && cur1[0] <= 'z') || ('a' <= cur2[0] && cur2[0] <= 'z')) continue;
                    if (cur1 != cur2) good = 0;
                }
            }
            if (good) { 
                for (int i = 1; i <= n; ++i) { 
                    if (a[i] == to) a[i] = make_string(x);
                    if (b[i] == to) b[i] = make_string(x);
                }
                f = 1;
                break;
            }
        }
        if (!f) return cout << "NE\n", 0;
    }
    cout << "DA\n";
    return 0;
}

/*
    5
    x 3 x y 3
    x y 2 z 3 
*/  
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Incorrect 3 ms 3436 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 4 ms 3456 KB Output is correct
3 Correct 4 ms 3436 KB Output is correct
4 Correct 3 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 3436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1079 ms 3948 KB Time limit exceeded
2 Halted 0 ms 0 KB -