제출 #869149

#제출 시각아이디문제언어결과실행 시간메모리
869149tuannmZamjena (COCI18_zamjena)C++17
14 / 70
20 ms7920 KiB
#include<bits/stdc++.h> #define ii pair<int, int> #define ll pair<long long, long long> #define fi first #define se second #define pb push_back //#define ORDS using namespace std; #ifdef ORDS #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #endif const int mod[2] = {1000000007, 998244353}; const int N = 1e5 + 1; const string NAME = ""; const int lim = 2147483647; //const unsigned int lim = 4294967295; //const long long lim = 9223372036854775807; //const unsigned long long lim = 18446744073709551615; const int mset = 0x3f; const double pi = acos(-1); mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); int n; int x[N], y[N]; map<string, int> mp; string a[N], b[N]; #ifdef i128 ostream & operator << (ostream &out, const __int128 &x){ __int128 i = x; vector<int> digits; while(i > 0){ digits.pb(i % 10); i /= 10; } reverse(digits.begin(), digits.end()); for(auto x : digits) out << x; return out; } #endif void inp(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; } for(int i = 1; i <= n; ++i){ cin >> b[i]; } } void solve(){ for(int i = 1; i <= n; ++i){ if(a[i][0] >= '0' && a[i][0] <= '9'){ for(int j = 0; j < a[i].size(); ++j){ x[i] = x[i] * 10 + (a[i][j] - '0'); } } else x[i] = -1; if(b[i][0] >= '0' && b[i][0] <= '9'){ for(int j = 0; j < b[i].size(); ++j){ y[i] = y[i] * 10 + (b[i][j] - '0'); } } else y[i] = -1; } bool ok = true; for(int i = 1; i <= n; ++i){ if(x[i] == -1 && y[i] == -1) continue; if(x[i] == -1){ if(!mp[a[i]]) mp[a[i]] = y[i]; else ok = false; } if(y[i] == -1){ if(!mp[b[i]]) mp[b[i]] = x[i]; else ok = false; } } for(int i = 1; i <= n; ++i){ if(x[i] == -1 && mp[a[i]]) x[i] = mp[a[i]]; if(y[i] == -1 && mp[b[i]]) y[i] = mp[b[i]]; } for(int i = 1; i <= n; ++i){ if(x[i] == -1 && y[i] == -1) continue; if(x[i] == -1){ if(!mp[a[i]]) mp[a[i]] = y[i]; else x[i] = mp[a[i]]; } if(y[i] == -1){ if(!mp[b[i]]) mp[b[i]] = x[i]; else y[i] = mp[b[i]]; } } for(int i = 1; i <= n; ++i){ if(x[i] == -1 && mp[a[i]]) x[i] = mp[a[i]]; if(y[i] == -1 && mp[b[i]]) y[i] = mp[b[i]]; if(x[i] != y[i]) ok = false; } if(ok) cout << "DA"; else cout << "NE"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef TimeCalculation auto starttime = chrono::high_resolution_clock::now(); #endif if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } inp(); solve(); #ifdef TimeCalculation auto endtime = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(endtime - starttime).count(); cout << "\n=====" << "\nTime elapsed: " << duration << " ms\n"; #endif } /* 5 x 3 x y 3 x y 2 z 3 */

컴파일 시 표준 에러 (stderr) 메시지

zamjena.cpp: In function 'void solve()':
zamjena.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             for(int j = 0; j < a[i].size(); ++j){
      |                            ~~^~~~~~~~~~~~~
zamjena.cpp:66:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for(int j = 0; j < b[i].size(); ++j){
      |                            ~~^~~~~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zamjena.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...