QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557063#2575. Restricted Arraysstack343WA 523ms79940kbC++232.3kb2024-09-11 01:54:432024-09-11 01:54:43

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 01:54:43]
  • 评测
  • 测评结果:WA
  • 用时:523ms
  • 内存:79940kb
  • [2024-09-11 01:54:43]
  • 提交

answer

#pragma GCC optimize("Ofast")
 
#include <bits/stdc++.h>   
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;   
using namespace std;
#define ll long long
#define ld long double
#define nline "\n"
#define f first
#define s second
#define sz(x) (ll)x.size()
#define vl vector<ll>
const ll INF_MUL=1e13;
const ll INF_ADD=1e18;
#define all(x) x.begin(),x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------     
const ll MOD=998244353;
const ll MAX=1001000;
vector<pair<ll,ll>> adj[MAX];
ll val[MAX],valid,n,m,g=0;
void dfs(ll cur){
  if(!valid){
    return;
  }
  for(auto edge:adj[cur]){
    if(!valid){
      return;
    }
    ll node=edge.f,weight=edge.s;
    ll new_val=val[cur]+weight;
    if(g!=0){
      new_val%=g;
      new_val+=g;
      new_val%=g;
    }
    if(val[node]==-1){
      val[node]=new_val;
      dfs(node);
    }
    else if(new_val!=val[node]){
      g=__gcd(g,abs(val[node]-new_val));
      valid=0;
      return;
    }
  }
}
void solve(){ 
  cin>>n>>m;
  for(ll i=1;i<=m;i++){
    ll x,y; cin>>x>>y;
    adj[x].push_back({y,1});
    adj[y].push_back({x,-1});
  }
  while(1){
    valid=1;
    for(ll i=1;i<=n;i++){
      val[i]=-1;
    }
    for(ll i=1;i<=n;i++){
      if(val[i]==-1){
        val[i]=0;
        dfs(i);
      }
    }
    if(valid){
      break;
    }
  }
  vector<ll> ans;
  for(ll i=1;i<=n;i++){
    if((g%i)==0){
      ans.push_back(i);
    }
  }
  cout<<sz(ans)<<nline;
  for(auto i:ans){
    cout<<i<<" ";
  }
  cout<<nline;
  return;    
}  
int main()                                                                                 
{         
  ios_base::sync_with_stdio(false);                         
  cin.tie(NULL);                              
  ll test_cases=1;                 
  //cin>>test_cases;
  while(test_cases--){
    solve();
  }
  cout<<fixed<<setprecision(12);  
  cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; 
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4080kb

input:

3 3
1 2
2 3
3 1

output:

2
1 3 

result:

ok 3 number(s): "2 1 3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3916kb

input:

5 5
1 2
2 3
3 4
4 5
1 5

output:

2
1 3 

result:

ok 3 number(s): "2 1 3"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3880kb

input:

5 5
1 2
2 3
3 1
4 5
5 4

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

5 1
1 2

output:

5
1 2 3 4 5 

result:

ok 6 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 4104kb

input:

30 100
3 20
30 24
24 26
20 2
24 27
26 19
27 28
24 20
12 15
28 19
13 24
6 23
5 19
12 3
22 24
30 16
22 25
13 19
27 20
14 30
3 23
29 13
25 3
9 7
6 8
20 24
11 27
19 1
16 14
21 21
20 15
8 11
29 6
27 28
3 19
10 24
5 2
6 1
18 25
19 4
10 23
5 23
18 3
26 19
10 13
23 14
28 11
19 28
6 15
7 23
28 25
8 30
1 12
2...

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3944kb

input:

300 1000
151 103
150 103
170 195
168 79
210 299
138 44
152 217
263 79
241 261
257 75
197 296
292 158
115 250
266 12
123 8
238 38
108 183
52 256
298 47
203 248
137 33
240 213
256 201
132 228
291 248
138 14
285 116
126 136
267 11
35 238
291 264
138 13
94 202
216 177
163 211
136 95
25 102
119 68
181 18...

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #7:

score: 0
Accepted
time: 4ms
memory: 4760kb

input:

3000 10000
973 1816
41 321
1446 869
2878 1009
1845 2170
937 973
537 241
424 2754
2148 551
2667 1398
367 1103
2306 1095
723 2854
1681 756
2008 792
1923 1714
2826 1250
148 256
887 1966
2758 2323
1482 1554
981 2331
987 1065
2075 1884
725 200
1565 1622
1231 746
1723 1230
1236 1549
1860 2075
1507 1027
16...

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #8:

score: 0
Accepted
time: 15ms
memory: 11044kb

input:

30000 100000
9507 4148
28742 7519
22004 7377
7494 3499
10238 2345
12942 25667
9310 24450
24360 18277
18839 1669
15280 15095
12927 12433
27142 5951
13026 311
9600 11754
16894 7756
14261 838
24374 14218
26787 12807
15616 16670
17561 29094
16583 24444
18526 20317
18553 20743
26072 2124
2185 6361
14086 ...

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #9:

score: 0
Accepted
time: 439ms
memory: 77076kb

input:

300000 1000000
249774 172530
147057 50829
236567 253049
47854 212292
133460 198836
125633 192588
281891 33774
140778 48640
100742 41970
189198 133279
269315 7059
133013 123981
36613 111461
60970 7696
63896 5697
21311 190163
188496 10885
162822 215590
218083 186866
285081 286524
123242 35980
198034 4...

output:

1
1 

result:

ok 2 number(s): "1 1"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3952kb

input:

30 100
22 19
2 28
14 16
30 11
2 28
29 12
22 19
5 27
8 13
1 6
24 22
20 4
7 30
10 11
3 24
27 20
17 15
14 16
2 28
11 9
22 19
5 27
12 8
7 30
22 19
19 23
26 25
25 1
12 8
25 21
24 22
13 26
10 11
11 9
21 7
11 9
30 11
27 20
10 11
27 20
15 21
4 29
27 20
15 1
14 16
30 11
25 1
23 2
17 25
1 6
28 5
12 8
19 23
28...

output:

8
1 2 3 4 6 8 12 24 

result:

ok 9 numbers

Test #11:

score: 0
Accepted
time: 2ms
memory: 4028kb

input:

300 1000
215 14
81 196
92 279
242 189
294 229
99 274
119 103
82 213
259 222
160 158
51 109
82 213
192 286
240 172
206 166
15 277
160 158
49 244
94 86
6 15
251 194
259 222
246 117
79 234
194 67
171 300
200 171
171 300
167 273
60 145
231 83
146 19
132 48
224 232
226 78
191 10
174 121
149 299
83 252
81...

output:

20
1 2 3 4 5 6 8 10 12 15 16 20 24 30 40 48 60 80 120 240 

result:

ok 21 numbers

Test #12:

score: 0
Accepted
time: 4ms
memory: 4556kb

input:

3000 10000
1346 613
488 2191
851 2354
275 1318
1889 821
946 877
1879 384
10 1841
801 2924
2237 1054
2140 1368
1007 1635
323 2980
1517 1576
2358 1261
2317 624
2832 2365
2910 1956
2244 2960
1564 2465
426 1126
355 2060
2133 2512
1452 2129
2884 2410
290 1056
259 602
2068 2985
2782 1520
848 1419
943 824
...

output:

48
1 2 3 4 5 6 7 8 9 10 12 14 15 18 20 21 24 28 30 35 36 40 42 45 56 60 63 70 72 84 90 105 120 126 140 168 180 210 252 280 315 360 420 504 630 840 1260 2520 

result:

ok 49 numbers

Test #13:

score: 0
Accepted
time: 29ms
memory: 11472kb

input:

30000 100000
27763 27613
18741 22824
22122 19637
11395 1271
19897 2209
26279 11087
5539 18909
13336 11727
5590 28203
3117 24690
13407 10952
13973 17613
2556 568
25401 27125
4987 27767
18068 25667
15097 16341
12826 19732
682 20475
11755 6501
5998 23752
1148 8092
3726 29463
23528 4735
12687 17530
2948...

output:

96
1 2 3 4 5 6 7 8 9 10 11 12 14 15 18 20 21 22 24 28 30 33 35 36 40 42 44 45 55 56 60 63 66 70 72 77 84 88 90 99 105 110 120 126 132 140 154 165 168 180 198 210 220 231 252 264 280 308 315 330 360 385 396 420 440 462 495 504 616 630 660 693 770 792 840 924 990 1155 1260 1320 1386 1540 1848 1980 231...

result:

ok 97 numbers

Test #14:

score: 0
Accepted
time: 523ms
memory: 79940kb

input:

300000 1000000
95735 7078
271979 37223
50786 10310
217441 245346
229845 227925
242582 42827
165670 64385
181116 137966
245475 297918
173565 24747
30795 91894
84189 253442
37632 38718
59779 74589
23315 23433
281979 211022
158778 101311
236318 245
170058 23297
251247 46053
133822 94039
94988 67932
984...

output:

180
1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 18 20 21 22 24 25 28 30 33 35 36 40 42 44 45 48 50 55 56 60 63 66 70 72 75 77 80 84 88 90 99 100 105 110 112 120 126 132 140 144 150 154 165 168 175 176 180 198 200 210 220 225 231 240 252 264 275 280 300 308 315 330 336 350 360 385 396 400 420 440 450 462 495...

result:

ok 181 numbers

Test #15:

score: -100
Wrong Answer
time: 0ms
memory: 3924kb

input:

30 100
10 24
11 25
3 27
6 5
10 24
13 16
19 10
14 23
21 26
8 22
10 24
1 23
30 1
15 17
3 27
16 28
6 5
19 10
18 3
4 30
2 12
2 12
6 5
10 24
14 23
23 16
24 30
17 9
2 12
11 25
15 28
13 16
14 23
23 16
7 11
12 18
3 27
4 30
19 10
11 25
21 26
16 28
6 5
24 30
15 28
7 11
21 26
20 14
10 24
21 26
16 28
8 22
23 16...

output:

1
1 

result:

wrong answer 1st numbers differ - expected: '30', found: '1'