Submission #111345

# Submission time Handle Problem Language Result Execution time Memory
111345 2019-05-14T22:27:39 Z aleksami Pictionary (COCI18_pictionary) C++14
140 / 140
291 ms 18388 KB
    #include <bits/stdc++.h>
     
    using namespace std;
    #define MAXN 100005
    typedef pair<int,int> pii;
    int n,m,q;
    vector <int> comps[MAXN];
    int par[MAXN];
    vector <pii> events[MAXN];
     
    void init()
    {
      for(int i = 1; i <= n; i++)comps[i].push_back(i),par[i]=i,events[i].push_back({0,i});
    }
     
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin >> n >> m >> q;
      init();
      for(int i = m; i >= 1; i--)
      {
        int mx = par[i];
        for(int j = i; j <= n; j+=i)
        {
          if(comps[mx].size()<comps[par[j]].size())mx=par[j];
        }
        for(int j = i; j <= n; j+=i)
        {
          if(par[j]==mx)continue;
          int compid = par[j];
          for(auto x:comps[compid])
          {
            comps[mx].push_back(x);
            par[x]=mx;
            events[x].push_back({m-i+1,mx});
          }
          comps[compid].clear();
        }
      }
      while(q--)
      {
        int a,b;
        cin >> a >> b;
        int ans = m;
        for(auto x:events[a])
        {
          for(auto y:events[b])
          {
            if(x.second==y.second)ans=min(ans,max(x.first,y.first));
          }
        }
        cout << ans << " ";
      }
      return 0;
    }
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 5376 KB Output is correct
2 Correct 119 ms 5400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 5608 KB Output is correct
2 Correct 148 ms 5472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 7800 KB Output is correct
2 Correct 98 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 9592 KB Output is correct
2 Correct 110 ms 9364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 11388 KB Output is correct
2 Correct 129 ms 11444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 9964 KB Output is correct
2 Correct 219 ms 14456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 15544 KB Output is correct
2 Correct 269 ms 16952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 18272 KB Output is correct
2 Correct 291 ms 18388 KB Output is correct