Submission #1406385
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
int main()
{
int n,q;
scanf(" %d %d", &n, &q);
vector<int> a(q),b(q);
rep(i,q)
{
scanf(" %d %d", &a[i], &b[i]);
--a[i];
--b[i];
}
vector<int> x(n),pos(n),fin(n);
iota(all(x),0);
iota(all(pos),0);
iota(all(fin),0);
rep(i,q)
{
swap(pos[x[a[i]]],pos[x[b[i]]]);
swap(x[a[i]],x[b[i]]);
}
vector<int> ans(n);
for(int j=-1; j<=1; ++j)
{
int nx = pos[0]+j;
if(0<=nx && nx<n) ans[nx]=1;
}
for(int i=q-1; i>=0; --i)
{
swap(pos[x[a[i]]],pos[x[b[i]]]);
swap(fin[x[a[i]]],fin[x[b[i]]]);
swap(x[a[i]],x[b[i]]);
for(int j=-1; j<=1; ++j)
{
int nx = pos[0]+j;
if(0<=nx && nx<n) ans[nx]=1;
}
}
printf("%d\n", accumulate(all(ans),0));
return 0;
}
Submission Info
Submission Time |
|
Task |
G - Magician |
User |
imulan |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1396 Byte |
Status |
WA |
Exec Time |
21 ms |
Memory |
2560 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:16:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &n, &q);
^
./Main.cpp:20:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %d %d", &a[i], &b[i]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
sample_01.txt, sample_02.txt, sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
subtask1_01.txt |
WA |
21 ms |
2560 KB |
subtask1_02.txt |
WA |
21 ms |
2560 KB |
subtask1_03.txt |
WA |
21 ms |
2560 KB |
subtask1_04.txt |
WA |
21 ms |
2560 KB |
subtask1_05.txt |
WA |
21 ms |
2560 KB |
subtask1_06.txt |
WA |
21 ms |
2560 KB |
subtask1_07.txt |
WA |
21 ms |
2560 KB |
subtask1_08.txt |
WA |
21 ms |
2560 KB |
subtask1_09.txt |
AC |
21 ms |
2560 KB |
subtask1_10.txt |
WA |
21 ms |
2560 KB |
subtask1_11.txt |
WA |
21 ms |
2560 KB |
subtask1_12.txt |
WA |
21 ms |
2560 KB |
subtask1_13.txt |
WA |
21 ms |
2560 KB |
subtask1_14.txt |
WA |
21 ms |
2560 KB |
subtask1_15.txt |
AC |
21 ms |
2560 KB |
subtask1_16.txt |
WA |
21 ms |
2560 KB |
subtask1_17.txt |
AC |
21 ms |
2560 KB |
subtask1_18.txt |
AC |
21 ms |
2560 KB |
subtask1_19.txt |
WA |
21 ms |
2560 KB |