#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
int INF=1e9+10;
int main() {
//ios::sync_with_stdio(0);
//cin.tie(0);
//freopen("test_input.txt", "r", stdin);
//freopen("test_output.txt", "w", stdout);
int k,n;cin>>k>>n;
vector<pair<char,int>> a(n),b(n);
REP(i,0,n)cin>>a[i].F>>a[i].S>>b[i].F>>b[i].S;
//cout<<"a";
ll ans=0;
pii c;
REP(i,0,n){
if(a[i].F==b[i].F){
ans+=(ll)abs(a[i].S-b[i].S);
}
else c.PB({a[i].S,b[i].S});
}
int m=c.size();
//sort(c.begin(),c.end());
if(k==1){
vi ar;
REP(i,0,m)ar.PB(c[i].F);
REP(i,0,m)ar.PB(c[i].S);
sort(ar.begin(),ar.end());
//REP(i,0,2*m)cout<<ar[i]<<" ";
REP(i,0,m*2)ans+=(ll)abs(ar[i]-ar[m]);
cout<<ans+(ll)m;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
38 ms |
5064 KB |
Output is correct |
13 |
Correct |
82 ms |
6360 KB |
Output is correct |
14 |
Correct |
54 ms |
5192 KB |
Output is correct |
15 |
Correct |
50 ms |
3788 KB |
Output is correct |
16 |
Correct |
65 ms |
5828 KB |
Output is correct |
17 |
Correct |
83 ms |
6340 KB |
Output is correct |
18 |
Correct |
67 ms |
6084 KB |
Output is correct |
19 |
Correct |
82 ms |
6440 KB |
Output is correct |
20 |
Correct |
67 ms |
6120 KB |
Output is correct |
21 |
Correct |
75 ms |
6220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |