# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
712677 |
2023-03-19T13:01:50 Z |
vanic |
Dijamant (COI16_dijament) |
C++14 |
|
2000 ms |
4216 KB |
//celinov kod
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define msi multiset<int>
#define si set<int>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = mod;
const ll INF = 1e18;
const int logo = 20;
const int MAXN = 1e3 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
bitset<MAXN> cvis[MAXN][2], need[2];
vi g[MAXN], pg[MAXN], r[MAXN];
int nod = 1, pnod = 1, indeg[MAXN];
map<string, int> ids, pids;
string fir;
vector<string> inp;
vi topo, st, sus;
void failalo(){
FOR(i, 1, nod + 1) g[i] = pg[i];
nod = pnod;
ids = pids;
cout << "greska\n";
}
void scan(int &a){
a=0;
char c=getchar();
while(c>='0' && c<='9'){
a*=10;
a+=c-'0';
c=getchar();
}
}
void scanline(){
fir.clear();
inp.clear();
char c = getchar();
while(c<'a' || c>'z'){
c=getchar();
}
while(c != ' ') fir.PB(c), c = getchar();
getchar();
getchar();
c = getchar();
string s1;
while(c != ';'){
while(c != ' ') s1.PB(c), c = getchar();
inp.PB(s1);
s1.clear();
c = getchar();
}
getchar();
}
void check(){
pids = ids;
pnod = nod;
FOR(i, 1, nod + 1){
pg[i] = g[i];
indeg[i] = 0;
r[i].clear();
cvis[i][0].reset();
cvis[i][1].reset();
}
scanline();
if(ids[fir]){
failalo();
return;
}
ids[fir] = nod++;
sus.clear();
for(auto &cur : inp){
if(ids[cur]) sus.PB(ids[cur]);
else{
failalo();
return;
}
}
for(auto &x : sus) g[x].PB(nod - 1);
FOR(j, 1, nod) for(auto &x : g[j]) indeg[x]++, r[x].PB(j);
topo.clear(), st.clear();
FOR(j, 1, nod) if(indeg[j] == 0) st.PB(j);
while(!st.empty()){
int u = st.back();
st.PPB();
topo.PB(u);
for(auto &x : g[u]) if(--indeg[x] == 0) st.PB(x);
}
for(auto &x : topo){
cvis[x][0][x] = 1;
for(auto &y : g[x]) cvis[y][0] |= cvis[x][0];
}
reverse(all(topo));
for(auto &x : topo){
cvis[x][1][x] = 1;
for(auto &y : r[x]) cvis[y][1] |= cvis[x][1];
}
FOR(j, 1, nod) FOR(i, 1, j){
if(cvis[i][1][j] or cvis[i][0][j]) continue;
need[0] = cvis[i][1] & cvis[j][1];
need[1] = cvis[i][0] & cvis[j][0];
need[0][i] = 0;
need[0][j] = 0;
need[1][i] = 0;
need[1][j] = 0;
if(need[0].count() and need[1].count()){
failalo();
return;
}
}
cout << "ok\n";
}
void solve(){
int n;
scan(n);
REP(i, n) check();
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin >> t;
while(t--)solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
428 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
428 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
6 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
6 ms |
340 KB |
Output is correct |
18 |
Correct |
6 ms |
440 KB |
Output is correct |
19 |
Correct |
4 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
340 KB |
Output is correct |
21 |
Correct |
7 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2054 ms |
4216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |