Submission #1120447

#TimeUsernameProblemLanguageResultExecution timeMemory
1120447vjudge1KOVANICE (COI15_kovanice)C++17
10 / 100
557 ms20524 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld double const int INF = 1e18; const int mod = 12345; const int sz = 4e3 + 5; signed main() { ios_base::sync_with_stdio(0);cin.tie(0); int n , m , v; cin >> n >> m >> v; vector < string > q1; vector < string > q2; for(int i = 1;i <= v;i++) { string s; cin >> s; bool f = 0; for(char c : s) { if(c == '=') { f = 1; q2.push_back(s); continue; } } if(!f) q1.push_back(s); } vector < int > ans(m + 1 , -1); for(int i = 0;i < q1.size();i++) { string s = q1[i]; string r1 = ""; string r2 = ""; int in = -1; char q; for(int j = 0;j < s.size();j++) { if(s[j] == '>' or s[j] == '<') { in = j; q = s[j]; break; } r1 += s[j]; } for(int j = in + 1;j < s.size();j++) r2 += s[j]; int x1 = stoi(r1); int x2 = stoi(r2); if(q == '<') { ans[x1] = 1; ans[x2] = 2; } else { ans[x1] = 2; ans[x2] = 1; } } vector < pair < int , int > > b; for(int i = 0;i < q2.size();i++) { string s = q2[i]; string r1 = ""; string r2 = ""; int in = -1; for(int j = 0;j < s.size();j++) { if(s[j] == '=') { in = j; break; } r1 += s[j]; } for(int j = in + 1;j < s.size();j++) r2 += s[j]; int x1 = stoi(r1); int x2 = stoi(r2); b.push_back({x1,x2}); } for(int i = 0;i < b.size();i++) { if(ans[b[i].second] != -1) { ans[b[i].first] = ans[b[i].second]; } else if(ans[b[i].first] != -1) { ans[b[i].second] = ans[b[i].first]; } } while(1) { int cnt = 0; for(int i = 0;i < b.size();i++) { if(ans[b[i].second] == -1 && ans[b[i].second] == 1) for(int j = 0;j < b.size();j++) { if(b[i].first == b[j].second && ans[b[j].second] != -1) { ans[b[i].first] = ans[b[j].second]; ans[b[i].second] = ans[b[j].first]; cnt++; } else if(b[i].first == b[j].first && ans[b[j].first] != -1) { ans[b[i].first] = ans[b[j].first]; ans[b[i].second] = ans[b[j].first]; cnt++; } else if(b[i].second == b[j].second && ans[b[j].second] != -1) { ans[b[i].second] = ans[b[j].second]; ans[b[i].first] = ans[b[j].second]; cnt++; } else if(b[i].second == b[j].first && ans[b[j].first] != -1) { ans[b[i].second] = ans[b[j].first]; ans[b[i].first] = ans[b[j].first]; cnt++; } } } if(!cnt) break; } for(int i = 0;i < b.size();i++) { if(ans[b[i].second] != -1) { ans[b[i].first] = ans[b[i].second]; } else if(ans[b[i].first] != -1) { ans[b[i].second] = ans[b[i].first]; } } for(int i = 1;i <= m;i++) { if(ans[i] == -1) { cout << "?" << endl; continue; } cout << 'K' << ans[i] << endl; } }

Compilation message (stderr)

kovanice.cpp: In function 'int main()':
kovanice.cpp:36:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    for(int i = 0;i < q1.size();i++)
      |                  ~~^~~~~~~~~~~
kovanice.cpp:43:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |        for(int j = 0;j < s.size();j++)
      |                      ~~^~~~~~~~~~
kovanice.cpp:53:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |        for(int j = in + 1;j < s.size();j++) r2 += s[j];
      |                           ~~^~~~~~~~~~
kovanice.cpp:68:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    for(int i = 0;i < q2.size();i++)
      |                  ~~^~~~~~~~~~~
kovanice.cpp:74:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |        for(int j = 0;j < s.size();j++)
      |                      ~~^~~~~~~~~~
kovanice.cpp:83:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |        for(int j = in + 1;j < s.size();j++) r2 += s[j];
      |                           ~~^~~~~~~~~~
kovanice.cpp:88:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |    for(int i = 0;i < b.size();i++)
      |                  ~~^~~~~~~~~~
kovanice.cpp:102:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |        for(int i = 0;i < b.size();i++)
      |                      ~~^~~~~~~~~~
kovanice.cpp:105:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |            for(int j = 0;j < b.size();j++)
      |                          ~~^~~~~~~~~~
kovanice.cpp:135:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |    for(int i = 0;i < b.size();i++)
      |                  ~~^~~~~~~~~~
kovanice.cpp:56:8: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |        if(q == '<')
      |        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...