답안 #40084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40084 2018-01-26T14:50:19 Z krauch Dijamant (COI16_dijament) C++14
100 / 100
507 ms 5196 KB
// Autor: Ante Derek

#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cassert>
#include <algorithm>

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " << 

using namespace std;

map<string, int> index;
vector<vector<int>> parents;

int process(const string &k, const vector<string> &p) {
  int m = index.size();
  if (index.count(k))
    return 0;
  vector<int> pp;
  for (auto x : p) {
    if (index.count(x) == 0)
      return 0;
    pp.push_back(index[x]);
  }
  sort(pp.begin(), pp.end());
  vector<int> seen(m, 0);
  for (int i=(int)pp.size()-1; i>=0; i--) {
    int y = pp[i];
    if (seen[y])
      continue ;
    for (auto z : parents[y]) {
      if (seen[z])
        return 0;
      seen[z] = 1;
    }
  }
  index[k] = m;
  for (auto y : pp)
    seen[y] = 1;
  parents.push_back(vector<int>());
  for (int i=0; i<m; i++)
    if (seen[i])
      parents[m].push_back(i);
  return 1;
}

int main() {
  int n;
  cin >> n;
  for (int i=0; i<n; i++) {
    string k;
    vector<string> p;
    string temp;
    cin >> k >> temp;
    assert(temp == ":");
    cin >> temp;
    while (temp != ";") {
      p.push_back(temp);
      cin >> temp;
    }
    if (process(k, p))
      cout << "ok" << endl;
    else
      cout << "greska" << endl;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 1 ms 2028 KB Output is correct
3 Correct 1 ms 2028 KB Output is correct
4 Correct 1 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 1 ms 2028 KB Output is correct
3 Correct 1 ms 2028 KB Output is correct
4 Correct 1 ms 2028 KB Output is correct
5 Correct 1 ms 2028 KB Output is correct
6 Correct 5 ms 2160 KB Output is correct
7 Correct 6 ms 2028 KB Output is correct
8 Correct 1 ms 2028 KB Output is correct
9 Correct 2 ms 2028 KB Output is correct
10 Correct 2 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2028 KB Output is correct
2 Correct 1 ms 2028 KB Output is correct
3 Correct 1 ms 2028 KB Output is correct
4 Correct 1 ms 2028 KB Output is correct
5 Correct 1 ms 2028 KB Output is correct
6 Correct 5 ms 2160 KB Output is correct
7 Correct 6 ms 2028 KB Output is correct
8 Correct 1 ms 2028 KB Output is correct
9 Correct 2 ms 2028 KB Output is correct
10 Correct 2 ms 2028 KB Output is correct
11 Correct 1 ms 2028 KB Output is correct
12 Correct 1 ms 2028 KB Output is correct
13 Correct 1 ms 2028 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 0 ms 2028 KB Output is correct
17 Correct 1 ms 2028 KB Output is correct
18 Correct 1 ms 2028 KB Output is correct
19 Correct 2 ms 2028 KB Output is correct
20 Correct 2 ms 2028 KB Output is correct
21 Correct 0 ms 2028 KB Output is correct
22 Correct 2 ms 2028 KB Output is correct
23 Correct 1 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 4972 KB Output is correct
2 Correct 507 ms 5196 KB Output is correct
3 Correct 257 ms 2180 KB Output is correct
4 Correct 5 ms 2160 KB Output is correct
5 Correct 6 ms 2160 KB Output is correct
6 Correct 19 ms 2164 KB Output is correct
7 Correct 20 ms 2164 KB Output is correct
8 Correct 41 ms 2160 KB Output is correct
9 Correct 47 ms 2160 KB Output is correct
10 Correct 21 ms 2160 KB Output is correct
11 Correct 14 ms 2160 KB Output is correct
12 Correct 429 ms 4832 KB Output is correct