Submission #1520310
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//----------------------//
int n, q;
bool dp[112345];
bool ok[112345];
int main() {
cin >> n >> q;
int p = 0;
REP(i, q) {
vector<pii> update;
int a, b;
scanf("%d %d", &a, &b);
a--; b--;
if (p > 0) dp[p - 1] = true;
if (p < n - 1) dp[p + 1] = true;
if (p == a) p = b;
else if (p == b) p = a;
swap(dp[a], dp[b]);
if (p > 0) dp[p - 1] = true;
if (p < n - 1) dp[p + 1] = true;
}
ok[p] = true;
REP(i, n) if (dp[i]) ok[i] = true;
int ans = 0;
REP(i, n) ans += ok[i];
cout << ans << endl;
return 0;
}
Submission Info
Submission Time
2017-08-19 22:18:20+0900
Task
G - Magician
User
tkmst201
Language
C++14 (GCC 5.4.1)
Score
100
Code Size
1207 Byte
Status
AC
Exec Time
18 ms
Memory
384 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:32:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 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
AC
18 ms
384 KB
subtask1_02.txt
AC
18 ms
384 KB
subtask1_03.txt
AC
18 ms
384 KB
subtask1_04.txt
AC
18 ms
384 KB
subtask1_05.txt
AC
18 ms
384 KB
subtask1_06.txt
AC
18 ms
384 KB
subtask1_07.txt
AC
18 ms
384 KB
subtask1_08.txt
AC
18 ms
384 KB
subtask1_09.txt
AC
18 ms
384 KB
subtask1_10.txt
AC
18 ms
384 KB
subtask1_11.txt
AC
18 ms
384 KB
subtask1_12.txt
AC
18 ms
384 KB
subtask1_13.txt
AC
18 ms
384 KB
subtask1_14.txt
AC
18 ms
384 KB
subtask1_15.txt
AC
18 ms
384 KB
subtask1_16.txt
AC
18 ms
384 KB
subtask1_17.txt
AC
18 ms
384 KB
subtask1_18.txt
AC
18 ms
384 KB
subtask1_19.txt
AC
18 ms
384 KB