Submission #712675

# Submission time Handle Problem Language Result Execution time Memory
712675 2023-03-19T12:58:10 Z vanic Dijamant (COI16_dijament) C++14
100 / 100
606 ms 7256 KB
#include <cstdio>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <assert.h>
#include <string.h>

using namespace std;

const int maxn=1005;

map < string, int > ind;
vector < int > ms[maxn];
bool spec[maxn];
int dp[maxn];

void scan(int &a){
  a=0;
  char c=getchar();
  while(c>='0' && c<='9'){
    a*=10;
    a+=c-'0';
    c=getchar();
  }
}

void scan1(string &s, vector < string > &v){
  s.clear();
  v.clear();
  char c=getchar();
  while(c!=' '){
    s.push_back(c);
    c=getchar();
  }
  getchar();
  getchar();
  c=getchar();
  string s1;
  while(c!=';'){
    while(c!=' '){
      s1.push_back(c);
      c=getchar();
    }
    v.push_back(s1);
    s1.clear();
    c=getchar();
  }
  getchar();
}

int dfs(int x){
  if(dp[x]){
    return dp[x];
  }
  int y;
  for(int i=0; i<ms[x].size(); i++){
    y=dfs(ms[x][i]);
    if(y==maxn){
      return maxn;
    }
    if(y!=-1){
      if(dp[x] && dp[x]!=dp[y]){
        return maxn;
      }
      dp[x]=y;
    }
  }
  if(!dp[x]){
    if(spec[x]){
      dp[x]=x;
    }
    else{
      dp[x]=-1;
    }
  }
  return dp[x];
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s, s1;
  vector < string > v;
  int p;
  bool sol;
  int iduc=1;
  for(int i=0; i<n; i++){
    cin >> s;
    cin >> s1;
    cin >> s1;
    v.clear();
    while(s1!=";"){
      v.push_back(s1);
      cin >> s1;
    }
    sol=1;
    if(ind.find(s)!=ind.end()){
      cout << "greska\n";
      continue;
    }
    for(int j=0; j<v.size(); j++){
      if(ind.find(v[j])==ind.end()){
        sol=0;
        break;
      }
    }
    if(!sol){
      cout << "greska\n";
      continue;
    }
    memset(spec, 0, sizeof(spec));
    for(int j=0; j<v.size(); j++){
      spec[ind[v[j]]]=1;
    }
    memset(dp, 0, sizeof(dp));
    for(int j=1; j<iduc; j++){
      if(!dp[j]){
        p=dfs(j);
        if(p==maxn){
          break;
        }
      }
    }
    if(p==maxn){
      cout << "greska\n";
      continue;
    }
    cout << "ok\n";
    ind[s]=iduc;
    for(int j=0; j<v.size(); j++){
      ms[ind[v[j]]].push_back(iduc);
    }
    iduc++;
  }

  return 0;
}

Compilation message

dijament.cpp: In function 'int dfs(int)':
dijament.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i=0; i<ms[x].size(); i++){
      |                ~^~~~~~~~~~~~~
dijament.cpp: In function 'int main()':
dijament.cpp:107:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     for(int j=0; j<v.size(); j++){
      |                  ~^~~~~~~~~
dijament.cpp:118:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(int j=0; j<v.size(); j++){
      |                  ~^~~~~~~~~
dijament.cpp:136:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  136 |     for(int j=0; j<v.size(); j++){
      |                  ~^~~~~~~~~
dijament.cpp:130:5: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
  130 |     if(p==maxn){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 2868 KB Output is correct
2 Correct 606 ms 7256 KB Output is correct
3 Correct 54 ms 4492 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 7 ms 468 KB Output is correct
7 Correct 10 ms 484 KB Output is correct
8 Correct 18 ms 756 KB Output is correct
9 Correct 16 ms 760 KB Output is correct
10 Correct 5 ms 488 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 443 ms 6140 KB Output is correct