답안 #1120447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1120447 2024-11-28T07:45:42 Z vjudge1 KOVANICE (COI15_kovanice) C++17
10 / 100
557 ms 20524 KB
#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

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 == '<')
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 357 ms 8232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 5484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 557 ms 20524 KB Output isn't correct
2 Halted 0 ms 0 KB -