답안 #620705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
620705 2022-08-03T08:25:47 Z 3omar_ahmed Zamjena (COCI18_zamjena) C++17
56 / 70
1000 ms 35936 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std ;
using namespace __gnu_pbds;

#define endl '\n'
#define ordered_set tree<pair < int ,int >,null_type,less<pair < int ,int >>,rb_tree_tag,tree_order_statistics_node_update>
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()
bool check(string x){
    return(x[0] >= '0' && x[0] <= '9');
}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0),cout.tie(0);

    int n ;
    cin >> n ;
    vector < string > a(n) , b(n);
    map < string , vector < int > > ind1 , ind2 ;
    for( auto &i : a )
        cin >> i;
    for( auto &i : b )
        cin >> i;
    for( int i = 0 ; i < n ; i++ ){
        if(!check(a[i])) ind1[a[i]].push_back(i);
        if(!check(b[i])) ind2[b[i]].push_back(i);
    }
    for( int i = 0 ; i < n ; i++ ){
        bool f1 = check(a[i]) , f2 = check(b[i]);
//        cout << f1 << ' ' << f2 << endl ;
        if( f1 && f2 ){
            if(a[i] != b[i])
                return cout << "NE" , 0;
        }
        else{
            vector < int > tmpind1 = ind1[(f1 ? b[i] : a[i] )];
            vector < int > tmpind2 = ind2[(f1 ? b[i] : a[i] )];
            ind1[(f1 ? b[i] : a[i] )].clear();
            ind2[(f1 ? b[i] : a[i] )].clear();
            for(int idx = 0 ; idx < tmpind1.size() ; idx++){
                a[tmpind1[idx]] = (f1 ? a[i] : b[i]);
                ind1[(f1 ? a[i] : b[i])].push_back(tmpind1[idx]);
            }
            for(int idx = 0 ; idx < tmpind2.size() ; idx++){
                b[tmpind2[idx]] = (f1 ? a[i] : b[i]);
                ind2[(f1 ? a[i] : b[i])].push_back(tmpind2[idx]);
            }
            if(check(a[i]) && check(b[i])){
                if(a[i] != b[i]) return cout << "NE" , 0;
            }
        }
    }
//    for(auto i :a)cout << i << ' '; cout <<endl;
//    for(auto i :b)cout << i << ' '; cout <<endl;
    cout << (a == b? "DA" : "NE");
    return 0 ;
}

Compilation message

zamjena.cpp: In function 'int main()':
zamjena.cpp:42:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int idx = 0 ; idx < tmpind1.size() ; idx++){
      |                               ~~~~^~~~~~~~~~~~~~~~
zamjena.cpp:46:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             for(int idx = 0 ; idx < tmpind2.size() ; idx++){
      |                               ~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1320 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 13 ms 1428 KB Output is correct
5 Correct 7 ms 1108 KB Output is correct
6 Correct 6 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 5684 KB Output is correct
2 Correct 76 ms 5352 KB Output is correct
3 Correct 245 ms 11728 KB Output is correct
4 Correct 96 ms 9292 KB Output is correct
5 Execution timed out 1051 ms 35936 KB Time limit exceeded
6 Halted 0 ms 0 KB -