답안 #308027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308027 2020-09-29T22:37:40 Z qiangbao Dijamant (COI16_dijament) C++
100 / 100
1046 ms 10748 KB
#include <iostream>
#include <vector>
#include <bitset>
#include <map>

#define pb push_back

using namespace std;

int n;
vector<int> top;
vector<int> father[1001];

int cnt=0;
map<string, int> topos;
bitset<1001> mp[1001];
bitset<1001> cur;
bool decla[1001];

int conflic[1001][1001];
bool vis[1001];

bool ans=true;

void up(int x)
{
    int i;

    if(vis[x])
        return;
    cur.set(x, 1), vis[x]=true;
    for(i=0;i<father[x].size();i++)
        up(father[x][i]);
}

int consis()
{
    int i, j;

    for(i=0;i<=1000;i++)
        vis[i]=false;
    for(i=0;i<top.size();i++)
        up(top[i]);
    for(i=0;i<top.size();i++){
        for(j=i+1;j<top.size();j++){
            int x=top[i], y=top[j];
            if(conflic[x][y]==0){
                if(mp[x].test(y)==1 || mp[y].test(x)==1)
                    conflic[x][y]=conflic[y][x]=-1;
                else{
                    bitset<1001> f=mp[x]&mp[y];
                    if(f.count()>=1)
                        conflic[x][y]=conflic[y][x]=1;
                }
            }
            if(conflic[x][y]==1)
                return 0;
        }
    }

    return 1;
}

void wk()
{
    string in;
    int x;
    ans=true;

    cin >> in;
    if(!topos[in])
        topos[in]=++cnt;
    x=topos[in];
    cin >> in;

    top.clear();
    while(in!=";"){
        cin >> in;
        if(in==";")
            break;
        if(!topos[in])
            topos[in]=++cnt;
        top.pb(topos[in]);
        if(!decla[topos[in]])
            ans=false;
    }

    cur.reset();
    if(decla[x])
        ans=false;
    if(ans && !consis())
        ans=false;
    if(ans)
        decla[x]=true, mp[x]=cur, father[x]=top;

    if(ans)
        cout << "ok" << endl;
    else
        cout << "greska" << endl;
}

int main()
{
    ios_base:: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int i;

    cin >> n;
    for(i=1;i<=n;i++)
        wk();

    return 0;
}

Compilation message

dijament.cpp: In function 'void up(int)':
dijament.cpp:32:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(i=0;i<father[x].size();i++)
      |             ~^~~~~~~~~~~~~~~~~
dijament.cpp: In function 'int consis()':
dijament.cpp:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(i=0;i<top.size();i++)
      |             ~^~~~~~~~~~~
dijament.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(i=0;i<top.size();i++){
      |             ~^~~~~~~~~~~
dijament.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(j=i+1;j<top.size();j++){
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 896 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 1 ms 640 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 905 ms 9752 KB Output is correct
2 Correct 1046 ms 10748 KB Output is correct
3 Correct 408 ms 4860 KB Output is correct
4 Correct 5 ms 1408 KB Output is correct
5 Correct 7 ms 2304 KB Output is correct
6 Correct 14 ms 1920 KB Output is correct
7 Correct 23 ms 2048 KB Output is correct
8 Correct 42 ms 2044 KB Output is correct
9 Correct 51 ms 2040 KB Output is correct
10 Correct 14 ms 1536 KB Output is correct
11 Correct 14 ms 1280 KB Output is correct
12 Correct 808 ms 9576 KB Output is correct