Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; vector<int> imos(n + 2, 0); for(int i = 0; i < m; i++){ int c, d; cin >> c >> d; if(c < d){ imos[c]++; imos[d]--; } } for(int i = 1; i <= n + 1; i++){ imos[i] += imos[i - 1]; } int counter = 0; for(int i = 0; i <= n + 1; i++){ if(imos[i] > 0) counter++; } cout << n + 1 + counter * 2 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/************************************************************************* > File Name: 3.cpp > Author: cy > Mail: [email protected] > Created Time: 15/5/13 20:28:00 ************************************************************************/ #include<iostream> #include<cstring> #include <algorithm> #include<cstdlib> #include<vector> #include<cmath> #include<stdlib.h> #include<iomanip> #include<list> #include<deque> #include<map> #include <stdio.h> #include <queue> const int maxn=1000+5; #define inf 0x3f3f3f3f #define INF 0x3FFFFFFFFFFFFFFFLL #define rep(i,n) for(i=0;i<n;i++) #define reP(i,n) for(i=1;i<=n;i++) #define ull unsigned long long #define ll long long #define cle(a) memset(a,0,sizeof(a)) using namespace std; int n,m; struct node { int be,en; }tree[maxn]; vector<node>V; void init(){ V.clear(); } bool cmp(node a,node b){ return a.be<b.be; } void doit(){ node a; V.push_back(tree[0]); for(int i=1;i<m;i++){ a=V[V.size()-1]; if(tree[i].en>a.en&&tree[i].be<=a.en){ a.en=tree[i].en; V[V.size()-1]=a; } else if(tree[i].be>a.en){ V.push_back(tree[i]); } } } ll ans; ll work(){ int now=0; ans=0; int len=V.size(); for(int i=0;i<len;i++) { ans+=(V[i].en-now); ans+=(2*(V[i].en-V[i].be)); now=V[i].en; } ans+=(n+1-now); return ans; } int main() { #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); #endif while(cin>>n>>m){ init(); for(int i=0;i<m;i++){ cin>>tree[i].be>>tree[i].en; } sort(tree,tree+m,cmp); doit(); work(); cout<<ans<<endl; } return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <string> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <numeric> #include <sstream> #include <cmath> #include <cstdlib> #include <cstring> #include <tuple> #include <stack> using namespace std; #define rep(i,n) for(int i = 0; i<n ; i++) #define FOR(i,a,n) for(int i=a; i<n; i++) #define REPSTR(i,s) for(int i=0; (s)[i]; i++) #define REPITR(i,s) for(auto i=(s).begin(); i!=(s).end();i++) #define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b)) #define pb push_back #define mp make_pair #define ALL(a) (a).begin(), (a).end() #define EXIST(s,x) ((s).find(x)!=(s).end()) #define SET(a,c) memset(a,c,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #ifdef _DEBUG #define DEBUG(x) cerr<<#x<<":"<<x<<endl #else #define DEBUG(x) #endif #define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl #define INF 1001001001 #define LLINF 1001001001001001001LL typedef long long ll; typedef pair<int, int> PII; typedef vector<int> VI; typedef stringstream SS; #define PQ priority_queue #define FST first #define SEC second int dx[4] = { 1,0,-1,0 }; int dy[4] = { 0,1,0,-1 }; bool revert[1123]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin>>n>>m; rep(i, m){ int c, d; cin>>c>>d; FOR(j, c, d) { revert[j]=true; } } int ans=0; rep(i, n){ ans+=revert[i]*2+1; } cout<<ans+1<<endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int IINF = INT_MAX; void chmin(int &a, int b){a=min(a,b);}; int main() { int n, m; cin >> n >> m; vector<int> a(n+2, n+1); vector<vector<int> > dp(n+2, vector<int>(n+2, IINF/2)); for(int i=0;i<m;i++){ int c, d; cin >> c >> d; a[d] = min(a[d], c); } dp[0][n+1] = 0; for(int i=0;i<=n;i++){ for(int j=1;j<=n+1;j++){ chmin(dp[i+1][min(j, a[i+1])],dp[i][j]+1); if(j<n+1){ chmin(dp[i+1][min(n+1, a[i+1])], dp[i][j] + abs(i-j)*2+1); } } } cout << dp[n+1][n+1] << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int main(){ int N, m; cin >> N >> m; vector< bool > shop(N + 1, 0); for(int i = 0; i < m; ++i){ int c, d; cin >> c >> d; fill( shop.begin() + c, shop.begin() + d, true); } cout << N + 1 + count(shop.begin(), shop.end(), true) * 2 << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define mp make_pair #define pb push_back #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<int,int> P; const LL mod=1000000007; const LL LINF=1LL<<62; const LL INF=1<<17; int main(){ int N,m;cin >> N >> m; vector<P> v; for (int i = 0; i < m; i++) { int c,d; cin >> c >> d; v.pb({c,d}); } v.pb({N+1,N+1}); sort(ALL(v)); int ans=0; int d=0,mx=v[0].fs,mi=v[0].sc; for (int i = 0; i < m+1; i++) { P p=v[i]; if(p.fs>mx){ ans+=mx-d+2*(mx-mi); mi=INF; d=mx; } mx=max(mx,p.sc); mi=min(mi,p.fs); } ans+=N+1-d; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<set> #include<list> #include<queue> #include<cmath> #include<functional> #include<algorithm> #define INF (1<<29) #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; struct Range{ int s,e; Range(){} Range(int s,int e):s(s),e(e){} bool operator<(const Range &r)const{return e<r.e;} }; vector<Range> merge_range(vector<Range> r){ vector<Range> res; sort(r.begin(),r.end()); for(int i=0;i<(int)r.size();i++){ int mi=r[i].s; while(!res.empty()&&r[i].s<=res.back().e){ mi=min(mi,res.back().s); res.pop_back(); } res.push_back(Range(mi,r[i].e)); } return res; } int main(){ int n,m; Range r[500]; cin>>n>>m; rep(i,m)cin>>r[i].s>>r[i].e; int ans=n+1; vector<Range> vr(merge_range(vector<Range>(r,r+m))); rep(i,vr.size()){ ans+=(vr[i].e-vr[i].s)*2; } cout<<ans<<endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; typedef pair<int, int> P; const int INF = 1e9; int dp[510], nxt[510]; int main(){ int n, m; cin >> n >> m; vector<P> d(m); rep(i, 0, m){ cin >> d[i].first >> d[i].second; } sort(d.begin(), d.end()); rep(i, 0, m + 1) dp[i] = INF; dp[0] = 0; rep(i, 0, n + 1){ rep(j, 0, m + 1) nxt[j] = dp[j] + 1; rep(j, 0, m){ if(dp[j] >= INF) continue; int MIN = i + 1; rep(k, j, m){ if(d[k].second > i + 1) break; MIN = min(MIN, d[k].first); int cost = dp[j] + 1 + (i + 1 - MIN) * 2; // cout << i << ' ' << j << ' ' << k << ' ' << dp[j] << ' ' << cost << endl; nxt[k + 1] = min(nxt[k + 1], cost); } } swap(dp, nxt); } cout << dp[m] << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <fstream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <iomanip> #include <utility> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; int solve(void); int main(void) { while (solve()) { } return 0; } int solve(void) { ll N, m; cin >> N >> m; // 尺取り法 vector<ll> v(N+2, 0); vector<pll> cd(N); for(auto& p: cd) { cin >> p.first >> p.second; v[p.first] ++; v[p.second] --; } for (int i = 0; i < v.size() - 1; i++) { v[i + 1] += v[i]; } pll segment; vector<pll> seg; for (int i = 1; i < v.size() - 1; i++) { if (v[i - 1] == 0 && v[i] > 0) { segment.first = i; } if (v[i] > 0 && v[i + 1] == 0) { segment.second = i + 1; seg.push_back(segment); } } ll ans = N + 1; for (const auto s : seg) { ans += abs(s.first - s.second) * 2; } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int N, m; int cum[1010]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin >> N >> m; for (int i = 0; i < m; i++) { int c, d; cin >> c >> d; cum[c]++; cum[d]--; } int ans = 0; for (int i = 0; i <= N; i++) { cum[i + 1] += cum[i]; ans += cum[i] > 0 ? 3 : 1; } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#define _CRT_SECURE_NO_WARNINGS #include"bits/stdc++.h" #ifdef _DEBUG #define DBG(n) n #else #define DBG(n) #endif #define INF 1e9 #define INFLL 1e18 #define EPS 1e-9 #define REP(i,n) for(ll i=0,i##_len=(n);i<i##_len;++i) #define REP1(i,n) for(ll i=1,i##_len=(n);i<=i##_len;++i) #define REPR(i,n) for(ll i=(n)-1;i>=0;--i) #define REPR1(i,n) for(ll i=(n);i>0;--i) #define REPC(i,obj) for(auto i:obj) #define ALL(obj) (obj).begin(),(obj).end() #define SETP(n) cout << fixed << setprecision(n) using namespace std; using ll = long long; template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; } signed main() { int n = in(), m = in(); vector<int>imos(n + 1); REP(i, m) { int c = in(), d = in(); ++imos[c]; --imos[d]; } REP(i, n)imos[i + 1] += imos[i]; int len = 0; REP(i, n + 1)if (imos[i] != 0)++len; cout << n + len * 2 + 1 << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define repp(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl; #define CNO cout<<"No"<<endl; typedef long long LL; typedef long double LD; int main(){ int n,m; cin >> n >> m; vector<int> p(n,0); int a,b; rep(i,m){ cin >> a >> b; a--,b--; repp(i,a,b){ p[i]++; } } int ans=n+1; rep(i,n) if(p[i]>0) ans+=2; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Integer.parseInt; /** * Shopping */ public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; String[] words; line = br.readLine(); int N, m; N = parseInt(line.substring(0, line.indexOf(' '))); m = parseInt(line.substring(line.indexOf(' ') + 1)); if (m == 0) { System.out.println(N + 1); return; } int[] shops = new int[N + 1]; for (int i = 0; i < m; i++) { line = br.readLine(); int c, d; c = parseInt(line.substring(0, line.indexOf(' '))); d = parseInt(line.substring(line.indexOf(' ') + 1)); shops[c]++; shops[d]--; } int zero = 0; for (int i = 1; i < shops.length; i++) { shops[i] += shops[i - 1]; if (shops[i] == 0) zero++; } System.out.println(zero + 1 + (N + 1 - (zero + 1)) * 3); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; int n, m; int table[2000]; int ans; int main(){ scanf("%d%d",&n,&m); ans = n+1; rep(i,m){ int c, d; scanf("%d%d",&c,&d); table[c]++; table[d]--; } for(int i = 1; i < 2000; i++) table[i] += table[i-1]; for(int i = 0; i < 2000; i++) if(table[i]) ans += 2; cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i<ll(b); i++) #define rep(i,b) loop(i,0,b) #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define lb lower_bound #define ub upper_bound #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl) struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}}; #else #define dump(...) #endif template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os; } int N,m; int c[1010]; int d[1010]; bool flg[1010]; int main(){ int N; while(cin>>N){ cin >> m; memset(flg,0,sizeof(flg)); rep(i,m){ int a,b; cin >> a >> b; loop(i,a,b) flg[i] = true; } int ans = N+1; rep(i,N+1) ans += 2*flg[i]; cout << ans << endl; } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> using namespace std; int N,M; int r[1010] = {}; int main(){ cin >> N >> M; int c,d; for(int i=1;i<=M;i++){ cin >> c >> d; r[c+1]++; r[d+1]--; } for(int i=1;i<=N;i++) r[i] += r[i-1]; int ans = 0; for(int i=1;i<=N;i++){ if(r[i]>=1) ans += 3; else ans++; } cout << ++ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define mp make_pair #define pb push_back #define fi first #define se second typedef pair<int,int> pi; int main() { int n,m; cin >>n >>m; vector<pi> s; //c?????????d?????????????????¨?????? rep(i,m) { int c,d; scanf(" %d %d",&c,&d); if(c<d) s.pb(pi(c,d)); } sort(all(s)); int ans=n+1; int back=s[0].fi; int now=s[0].se; if(m>0) { rep(i,m-1) { if(now<s[i+1].fi) { ans+=2*(now-back); back=s[i+1].fi; now=s[i+1].se; } else now=max(now,s[i+1].se); } ans+=2*(now-back); } printf("%d\n", ans); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <bitset> #include <cctype> #include <complex> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define range(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) range(i,0,n) #define clr(a,b) memset((a), (b) ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; const double eps = 1e-10; const double pi = acos(-1.0); const ll INF =1LL << 62; const int inf =1 << 29; int main(void){ for(int n, m, res; cin >> n >> m; cout << res << endl){ res = 0; vi once(n + 1, true); rep(i, m){ int c, d; cin >> c >> d; range(i, c, d){ once[i] = false; } } res = n + 1 + 2 * count(all(once), false); } return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<cstdio> using namespace std; bool rev[1010]; int main(){ int n,m,c,d,ans; scanf("%d%d",&n,&m); while(m--){ scanf("%d%d",&c,&d); for(int i=c;i<d;i++) rev[i]=true; } ans=n+1; for(int i=1;i<n;i++) if(rev[i]) ans+=2; printf("%d\n",ans); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); boolean[] triple = new boolean[n]; for (int i = 0; i < m; i++) { int c = sc.nextInt(); int d = sc.nextInt(); for (int j = c; j < d; j++) { triple[j] = true; } } int ans = 0; for (int i = 0; i < triple.length; i++) { if (triple[i]) { ans += 2; } } System.out.println(ans + n + 1); sc.close(); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<stdio.h> #include<algorithm> using namespace std; int p[1100]; int main(){ int a,b;scanf("%d%d",&a,&b); for(int i=0;i<a;i++){ int c,d; scanf("%d%d",&c,&d); for(int i=c;i<d;i++)p[i]++; } int ret=a+1; for(int i=1;i<=a;i++)if(p[i])ret+=2; printf("%d\n",ret); }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <utility> #include <cstring> #include <cmath> #include <queue> #include <set> #include <map> using namespace std; #define rep(i,n) for(int i=0; i<n; i++) typedef long long ll; typedef pair<int,int> pii; int main() { int n, m; cin >> n >> m; if(m==0) { cout << n+1 << endl; return 0; } vector<pii> cd(m); rep(i, m) { cin >> cd[i].first >> cd[i].second; } sort(cd.begin(), cd.end()); vector<pii> v; int s=cd[0].first, t=cd[0].second; for(int i=1; i<m; i++) { if(t <= cd[i].first) { v.push_back(pii(s,t)); s = cd[i].first; t = cd[i].second; } else { t = max(t, cd[i].second); } } v.push_back(pii(s,t)); int res = n+1; rep(i, v.size()) { res += (v[i].second - v[i].first)*2; } cout << res << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) void printv(vector<ll> v) { for (ll i : v) cout << i << endl; } int main() { int n, m; cin >> n >> m; vector<int> st(n + 1, 1); rep(i, m) { int c, d; cin >> c >> d; for (int j = c; j < d; j++) st[j] = 3; } cout << accumulate(st.begin(), st.end(), 0) << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i) #define rep(i,n) REP(i, 0, n) typedef long long int i64; typedef pair<int, int> pint; int a[1001]; int main() { int N, M; scanf("%d%d", &N, &M); int c, d; memset(a, 0, sizeof(a)); rep(_, M) { scanf("%d%d", &c, &d); --c; --d; a[c]++; a[d]--; } rep(i, N) a[i + 1] += a[i]; int ans = N + 1; int start = 0; bool cnt = false; rep(i, N + 1) { if(cnt == false) { if(a[i]) { cnt = true; start = i; } }else { if(a[i] == 0) { ans += (i - start) * 2; cnt = false; } } } printf("%d\n", ans); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <array> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #define REP(i, n) for (int i = 0; (i) < int(n); ++ (i)) using namespace std; int main() { // input int n, m; scanf("%d%d", &n, &m); vector<int> c(m), d(m); REP (i, m) scanf("%d%d", &c[i], &d[i]); // solve vector<int> imos(n + 2); REP (i, m) { imos[c[i]] += 1; imos[d[i]] -= 1; } int result = n + 1; REP (i, n + 1) { imos[i + 1] += imos[i]; result += 2 * bool(imos[i + 1]); } // output printf("%d\n", result); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); final int size = N + 2; int[] sum = new int[size]; for(int i = 0; i < M; i++){ final int from = sc.nextInt(); final int to = sc.nextInt(); sum[from] += 1; sum[to] -= 1; } for(int i = 1; i < size; i++){ sum[i] += sum[i - 1]; } //System.out.println(Arrays.toString(sum)); int ans = N + 1; for(int i = 0; i < size; i++){ if(sum[i] > 0){ ans += 2; } } System.out.println(ans); sc.close(); } public static class Scanner { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } // 他のnextXXXもXXX.parseXXX()メソッドを使って作れるので省略 public void close() throws IOException { br.close(); } } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.StringJoiner; import java.util.StringTokenizer; import java.util.function.Function; public class Main { static int N, M; static int[] C, D; public static void main(String[] args) { FastScanner sc = new FastScanner(System.in); N = sc.nextInt(); M = sc.nextInt(); C = new int[M]; D = new int[M]; for (int i = 0; i < M; i++) { C[i] = sc.nextInt(); D[i] = sc.nextInt(); } System.out.println(solve()); } static int solve() { int[][] ev = new int[M*2][2]; for (int i = 0; i < M; i++) { ev[i*2][0] = C[i]; ev[i*2][1] = 1; ev[i*2+1][0] = D[i]; ev[i*2+1][1] = -1; } Arrays.sort(ev, Comparator.<int[]>comparingInt(e -> e[0]).thenComparingInt(e -> -e[1])); int ans = N+1; int curr = 0; int from = -1; for (int[] e : ev) { int next = curr + e[1]; if( curr == 0 && next == 1 ) { from = e[0]; } else if( curr == 1 && next == 0 ) { int to = e[0]; ans += (to - from) * 2; from = -1; } curr = next; } return ans; } @SuppressWarnings("unused") static class FastScanner { private BufferedReader reader; private StringTokenizer tokenizer; FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } long nextLong() { return Long.parseLong(next()); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArray(int n, int delta) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt() + delta; return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } static <A> void writeLines(A[] as, Function<A, String> f) { PrintWriter pw = new PrintWriter(System.out); for (A a : as) { pw.println(f.apply(a)); } pw.flush(); } static void writeLines(int[] as) { PrintWriter pw = new PrintWriter(System.out); for (int a : as) pw.println(a); pw.flush(); } static void writeLines(long[] as) { PrintWriter pw = new PrintWriter(System.out); for (long a : as) pw.println(a); pw.flush(); } static int max(int... as) { int max = Integer.MIN_VALUE; for (int a : as) max = Math.max(a, max); return max; } static int min(int... as) { int min = Integer.MAX_VALUE; for (int a : as) min = Math.min(a, min); return min; } static void debug(Object... args) { StringJoiner j = new StringJoiner(" "); for (Object arg : args) { if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg)); else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg)); else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg)); else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg)); else j.add(arg.toString()); } System.err.println(j.toString()); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> int main() { int N, m; int c[2048]; int d[2048]; int imos[2048] = {}; std::cin >> N >> m; for(int i = 0; i < m; ++i) { std::cin >> c[i] >> d[i]; } for(int i = 0; i < m; ++i) { imos[c[i]] += 1; imos[d[i]] -= 1; } int t = 0; for(int i = 0; i <= N; ++i) { t += imos[i]; imos[i] = t; } int res = 0; for(int i = 0; i < N + 1; ++i) { if( imos[i] != 0 ) { res += 3; } else { res += 1; } } std::cout << res << std::endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <algorithm> using std::sort; using std::max; struct shop{ int l, r; }shops[1000]; int S; bool comp(shop a, shop b){ return a.l < b.l; } int main(){ int N, M; scanf("%d %d", &N, &M); N++; while(M--){ int l, r; scanf("%d %d", &l, &r); if(l < r){ shops[S].l = l; shops[S].r = r; S++; } } sort(shops, shops+S, comp); int MinL = 0; int MaxR = 0; for(int i=0;i<S;i++){ if(shops[i].l > MaxR){ N += (MaxR - MinL) * 2; MinL = shops[i].l; MaxR = shops[i].r; } MaxR = max(MaxR, shops[i].r); } N += (MaxR - MinL) * 2; printf("%d\n", N); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) //#define LOG(...) #define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i) #define REP(i, n) for(int i=0; i<(int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e)!=(s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SQ(n) (n) * (n) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { int N, m; cin >> N >> m; vi shop(N+10); REP(i, m){ int c, d; cin >> c >> d; shop[c-1]++; shop[d-1]--; } int res = N + 1; int cnt = 0; int start = -1; REP(i, N){ if(shop[i] == 0) continue; cnt += shop[i]; if(start == -1) start = i; if(cnt == 0) { res += (i - start) * 2; start = -1; } } cout << res << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> rng(m); for (auto &p: rng) cin >> p.first >> p.second, p.first--, p.second--; rng.emplace_back(0, 0); rng.emplace_back(n, n); sort(rng.begin(), rng.end()); int left = 0, right = 0; int ans = 0; for (auto p: rng) { if (right <= p.first) { ans += (right - left) * 3; ans += p.first - right; left = p.first, right = p.second; } else { right = max(right, p.second); } } cout << ans + 1 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define range(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) range(i,0,n) #define clr(a,b) memset((a), (b) ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; const double eps = 1e-10; const double pi = acos(-1.0); const ll INF =1LL << 62; const int inf =1 << 29; int c[510]; int d[510]; bool route[1010]; int main(void){ int n,m; cin >> n >> m; rep(i,m){ cin >> c[i]; cin >> d[i]; for(int j=c[i];j<d[i];++j) route[j]=true; } int ans=n+1; rep(i,n+1) if(route[i]) ans+=2; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(){ int N, m; cin >> N >> m; vector<int> c(m), d(m); for (int i = 0; i < m; i++){ cin >> c[i] >> d[i]; } vector<int> cnt(N + 1, 0); for (int i = 0; i < m; i++){ for (int j = c[i]; j < d[i]; j++){ cnt[j]++; } } int ans = N + 1; for (int i = 0; i <= N; i++){ if (cnt[i] > 0){ ans += 2; } } cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; int n,m,a,b; vector<P> t,u; vector<P> func(vector<P> t){ sort(t.begin(),t.end()); t.push_back(P(1e9,0)); int size=t.size(); vector<P> res; for(int i=0;i+1<size;i++){ if(t[i].second<t[i+1].first){ res.push_back(t[i]); }else{ t[i+1].first=t[i].first; t[i+1].second=max(t[i+1].second,t[i].second); } } return res; } int main(){ cin>>n>>m; for(int i=0;i<m;i++){ cin>>a>>b; t.push_back(P(a,b)); } t=func(t); int ans=n+1; for(int i=0;i<(int)t.size();i++) ans+=(t[i].second-t[i].first)*2; cout<<ans<<endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> typedef long long LL; #define SORT(c) sort((c).begin(),(c).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; int main(void) { int n,m; cin >> n >> m; int bac[1024]={}; REP(i,m){ int c,d; cin >> c >> d; bac[d-1]++; bac[c-1]--; } for(int i=n;i>0;--i) bac[i-1]+=bac[i]; int answer=0; REP(i,n+1) if(bac[i]) answer+=3; else answer+=1; cout << answer << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<list> #include<string> #include<algorithm> #include <utility> #include<stdio.h> #include<climits> using namespace std; int main(void){ int n,m; int c,d; int f[1000] = {}; cin >> n >> m; int i,j; for(i = 0;i < m;i++){ cin >> c >> d; for(j = c;j < d;j++){ f[j] = 1; } } for(i = 0,j = 0;i < n;i++){ if(f[i]) j++; } cout << n+1+2*j << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> using namespace std; int main(){ int n,m; cin >> n >> m; int p[1050]={}; int i,j,k; for(i=0;i<m;i++){ cin >> j >> k; p[j]=max(p[j],k); } int inf = 1<<15; int dp[1050][1050]; fill(dp[0],dp[1049],inf); dp[0][0]=0; i=0; for(j=max(i+1,p[i+1]);j<=n+1;j++){ dp[j][i+1]=min(dp[j][i+1],dp[i][i]+2*(j-i)-1); } for(i=1;i<=n+1;i++){ if(i>=p[i]) dp[i][i]=min(dp[i][i],dp[i-1][i-1]+1); for(j=p[i];j<=n+1;j++){ dp[j][i]=min(dp[j][i],dp[j][i-1]+1); } for(j=max(i+1,p[i+1]);j<=n+1;j++){ dp[j][i+1]=min(dp[j][i+1],dp[i][i]+2*(j-i)-1); } } //cout << dp[1000][2] << endl; /* for(i=0;i<=10;i++){ for(j=0;j<=10;j++){ //cout << dp[j][i] << " "; printf("%3d ", dp[j][i]); } cout << endl; } */ /* for(i=990;i<=1001;i++){ for(j=990;j<=1001;j++){ //cout << dp[j][i] << " "; printf("%3d ", dp[j][i]); } cout << endl; } */ int o=inf; o=min(o,dp[n+1][n+1]); cout << o << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define mp make_pair #define pb push_back #define fi first #define se second typedef pair<int,int> pi; int main() { int n,m; cin >>n >>m; vector<pi> s; //c?????????d?????????????????¨?????? rep(i,m) { int c,d; scanf(" %d %d",&c,&d); if(c<d) s.pb(pi(c,d)); } sort(all(s)); int ans=n+1; int back=s[0].fi; int now=s[0].se; if(m>0) { rep(i,m-1) { if(now<s[i+1].fi) { ans+=2*(now-back); back=s[i+1].fi; now=s[i+1].se; } else { now=max(now,s[i+1].se); } } ans+=2*(now-back); } printf("%d\n", ans); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include"bits/stdc++.h" using namespace std; using ll = int64_t; int main() { ll N, m; cin >> N >> m; vector<ll> restricts(N, -1); for (int i = 0; i < m; i++) { ll c, d; cin >> c >> d; c--; d--; restricts[c] = max(restricts[c], d); } ll ans = 0; ll left = INT_MAX; ll right = -1; for (ll curr_pos = 0; curr_pos < N; curr_pos++) { if (restricts[curr_pos] != -1) { right = max(right, restricts[curr_pos]); left = min(left, curr_pos); } else { if (curr_pos == right) { ans += 2 * (right - left); left = INT_MAX; } } ans++; } cout << ans + 1 << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; int n,m; bool b[3000]={}; int main(){ cin>>n>>m; while(m--){ int l,r; cin>>l>>r; for(int i=l;i<r;i++){ b[i]=true; } } int ans=0; for(int i=0;i<n+1;i++){ if(b[i]) ans+=3; else ans++; } cout<<ans<<endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; int main() { int N,m; cin >> N >> m; vector<int>backs(N, false); for (int i = 0; i < m; ++i) { int t, f; cin >> t >> f; t--; f--; for (int j = t; j < f; ++j) { backs[j] = true; } } int ans = 1+N + 2*accumulate(backs.begin(), backs.end(), 0); cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(){ int N,M; cin >> N >> M; vector< pair<int,int> > e; int ans = N + 1 ; for(int i = 0 ; i < M ; i++){ int a,b; cin >> a >> b; e.push_back(make_pair(a,b)); } if( M == 0 ){ cout << ans << endl; return 0; } sort(e.begin(),e.end()); int le = e[0].first; int ri = e[0].second; for(int i = 1 ; i < M ; i++){ if( ri < e[i].first ){ ans += 2 * (ri - le); le = e[i].first; ri = e[i].second; }else ri = max(ri,e[i].second); } ans += 2 * (ri-le); cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
python3
N, m = map(int, input().split()) v = [0]*N for i in range(m): c, d = map(int, input().split()) v[c-1] += 1 v[d-1] -= 1 s = 0; fst = 0 ans = N+1 for i in range(N): if s == 0 and v[i] > 0: fst = i s += v[i] if s == 0 and v[i] < 0: ans += (i - fst)*2 print(ans)
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> TUPLE; typedef vector<int> V; typedef vector<V> VV; typedef vector<VV> VVV; typedef vector<vector<int>> Graph; const int inf = 1e9; const int mod = 1e9 + 7; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int N, m; cin >> N >> m; vector<Pii> v(m); rep(i, m) cin >> v[i].first >> v[i].second; sort(all(v)); vector<Pii> u; rep(i, m) { if (!u.empty() && v[i].first <= u.back().second) { u.back().second = max(u.back().second, v[i].second); } else u.emplace_back(v[i]); } int ans = N + 1; for (auto p : u) { ans += 2 * (p.second - p.first); } cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;} template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template<class T> T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template<class T> T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1e9+7; constexpr lint INF = mod * mod; constexpr int MAX = 200010; int main(){ int n, m; scanf("%d%d", &n, &m); int a[n+2]; memset(a, 0, sizeof(a)); rep(i, m){ int c, d; scanf("%d%d", &c, &d); ++a[c]; --a[d]; } partial_sum(a, a+n+2, a); int ans = n+1; int l = 0; while(l < n+1){ if(a[l] == 0){ ++l; continue; } int r = l; while(r < n+1 && a[r] > 0) ++r; ans += (r-l) * 2; l = r; } printf("%d\n", ans); }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <sstream> #include <map> #include <set> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> P; int main() { int n, m; cin >> n >> m; vector<int> c(m), d(m); rep(i, m) cin >> c[i] >> d[i]; int cnt[1005]; memset(cnt, 0, sizeof(cnt)); rep(i, m) { REP(j, c[i], d[i]) { cnt[j]++; } } int ans = 3 * (n + 1); rep(i, n + 1) { if(cnt[i] == 0) { ans -= 2; } } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define MAX 600 struct rest{ int start, end; inline void set(int a, int b){ start = a; end = b; } bool operator < (const rest &a) const { return end < a.end; } } rests[MAX]; int n, m, restlen; bool exist[MAX]; int main(){ int a, b; while(scanf("%d%d", &n, &m) == 2){ restlen = 0; memset(exist, true, sizeof(exist)); for(int i = 0; i < m; i++){ scanf("%d%d", &a, &b); if(a < b){ rests[restlen].start = a; rests[restlen].end = b; restlen++; } } sort(rests, rests + restlen); for(int i = 0; i < m; i++){ for(int j = i - 1; j >= 0; j--) if(exist[j] && rests[j].end >= rests[i].start){ rests[i].start = min(rests[i].start, rests[j].start); exist[j] = false; } } int ans = n + 1; for(int i = 0; i < m; i++) if(exist[i]) ans += (rests[i].end - rests[i].start) << 1; printf("%d\n", ans); } return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define int long long #define MOD ((int)1e9+7) #define MAX 2000 int N, m, ans; int c[MAX], d[MAX]; int temp[MAX]; signed main(){ cin>>N>>m; for(int i = 0; i < m; i++){ cin>>c[i]>>d[i]; temp[c[i]]++; temp[d[i]]--; } for(int i = 0; i <= N; i++){ temp[i+1] += temp[i]; } for(int i = 1; i < N; i++){ if(temp[i]) ans += 2; } cout<<ans+N+1<<endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> int n,m; int c[501],d[501]; int cnt[1001]; int main(void){ scanf("%d %d",&n,&m); for(int i=0;i<m;i++){ scanf("%d %d",&c[i],&d[i]); for(int j=c[i];j<d[i];j++){ cnt[j]=1; } } int res=n+1; for(int i=0;i<=n;i++){ res+=cnt[i]*2; } printf("%d\n",res); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.*; public class Main { Scanner in = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main(){ new C().doIt(); } class C{ int n,c; ArrayList<Pair> list; void doIt(){ n = in.nextInt(); c = in.nextInt(); list = new ArrayList<Pair>(); for(int i=0;i<c;i++)list.add(new Pair(in.nextInt(), in.nextInt())); Collections.sort(list); // System.out.println(list); int[] hyou = new int[n+1]; for(int i=1;i<=n;i++){ hyou[i] = hyou[i-1]; for(int s=0;s<c;s++){ if(list.get(s).a==i)hyou[i]+=1; else if(list.get(s).b==i)hyou[i]-=1; } } int memo = -1; for(int i=1;i<=n;i++){ if(hyou[i]>0){ if(memo==-1)memo = i; hyou[i] = -1; }else{ if(hyou[i-1]==-1){ hyou[i] = memo; memo = -1; } } } int cnt = 0; for(int i=0;i<=n;i++){ if(hyou[i]>0){ cnt += (i-hyou[i])*2; } cnt++; } System.out.println(cnt); } class Pair implements Comparable<Pair>{ int a,b; public Pair(int a,int b) { this.a = a; this.b = b; } public int compareTo(Pair o) { return this.b-o.b; } public String toString(){ return "["+a+", "+b+"]"; } } } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/* * c.cc: */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_M = 500; /* typedef */ typedef pair<int,int> pii; /* global variables */ pii rvs[MAX_M]; /* subroutines */ /* main */ int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) cin >> rvs[i].first >> rvs[i].second; sort(rvs, rvs + m); int sum = 0, pci = -1, pdi = -1; for (int i = 0; i < m; i++) { int &ci = rvs[i].first, &di = rvs[i].second; if (pdi >= ci) { if (pdi < di) pdi = di; } else { sum += pdi - pci; pci = ci, pdi = di; } } sum += pdi - pci; printf("%d\n", n + 1 + sum * 2); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const double EPS = 1e-9; const int MOD = 1000000007; int N, M; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; vector<pair<int, int>> v; for (int i = 0; i < (M); i++) { int c, d; cin >> c >> d; v.push_back(make_pair(c, d)); } sort(v.begin(), v.end()); int ans = N + 1; int i = 0; while (i < M) { int s = i; while (i + 1 < M && v[i + 1].first <= v[i].second) i++; ans += (v[i].second - v[s].first) * 2; i++; } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long int N, M, ans = 0; cin >> N >> M; vector<int> data(N + 2); for (size_t i = 0; i < M; i++) { int a, b; cin >> a >> b; if (b > a) { data[a]++; data[b + 1]--; } } for (size_t i = 1; i < N + 2; i++) { data[i] += data[i - 1]; } ans += N + 1; long long int begin = 0, end; bool flag = 0, flag2 = 0; for (size_t i = 0; i < N + 2; i++) { if (data[i] > 0) { flag = 1; } if (data[i] == 0) { if (flag) { flag = 0; ans += (i - begin - 2) * 2; } begin = i; if (!flag2) { ans -= 2; flag2 = 1; } } } cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "["; for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { if (it != t.begin()) os << ","; os << *it; } os << "]"; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &t) { os << "{"; for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { if (it != t.begin()) os << ","; os << *it; } os << "}"; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } const int INF = 1 << 28; const double EPS = 1e-8; const int MOD = 1000000007; int n, m; int main() { ios::sync_with_stdio(false); cin >> n >> m; vector<pair<int, int> > segs; for (int i = 0; i < (int)(m); i++) { int l, r; cin >> l >> r; segs.emplace_back(l, r); } sort(segs.begin(), segs.end()); int ans = 0; int cur = 0; int back = 0; for (int i = 0; i < (int)(m); i++) { int l = segs[i].first; int r = segs[i].second; if (cur <= l) { ans += (cur - back) * 2; back = l; } cur = r; } cout << n + 1 + ans + (cur - back) * 2 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; struct Mod { long long int num; Mod() : num(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { ; } operator long long int() { return num; } }; Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); } Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); } Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); } Mod operator+=(Mod &a, Mod b) { return a = a + b; } Mod operator-=(Mod &a, Mod b) { return a = a - b; } Mod operator*=(Mod &a, Mod b) { return a = a * b; } Mod operator^(Mod a, int n) { if (n == 0) return Mod(1); Mod res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } Mod inv(Mod a) { return a ^ (mod - 2); } Mod operator/(Mod a, Mod b) { return a * inv(b); } Mod fact[1024000], factinv[1024000]; void init() { fact[0] = Mod(1); factinv[0] = 1; for (int i = 0; i < (int)(1024000 - 1); i++) { fact[i + 1] = fact[i] * Mod(i + 1); factinv[i + 1] = factinv[i] / Mod(i + 1); } } Mod comb(int a, int b) { return fact[a] * factinv[b] * factinv[a - b]; } long long int memo[20]; long long int powint(long long int a, int b) { if (b == 0) return 1; if (b == 1) return a; else { long long int ans = 1; long long int c = powint(a, b / 2); ans *= c * c; ans *= (b % 2) ? a : 1; return ans; } } int backnum[100000][20]; struct Node { Node(int aid) : children(), ancs() { id = (aid); for (int i = 0; i < 20; ++i) { ancs[i] = -1; } } int id; vector<int> children; array<int, 20> ancs; }; int main() { int N, M; cin >> N >> M; vector<int> Sa(N + 1); vector<int> Sum(N); for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; if (a < b) { Sa[a]++; Sa[b]--; } } int now = 0; for (int i = 0; i < N; ++i) { now += Sa[i]; Sum[i] += now; } int a = count_if(Sum.begin(), Sum.end(), [](const int l) { return l != 0; }); cout << N + 1 + a * 2; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, d, flg[1002] = {}; cin >> n >> d; for (int i = 0; i < d; i++) { int a, b; cin >> a >> b; flg[a] = max(flg[a], b); } int sta = 0, sum = 0, L, R; for (int i = 0; i <= n; i++) { if (flg[i] != 0 && sta == 1) R = max(R, flg[i]); else if (flg[i] != 0) L = i, R = flg[i], sta = 1; else if (i == R) sum += 3 * (R - L) + 1, sta = 0; else if (sta == 0) sum++; } cout << sum << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int dfs(int n, vector<vector<int> >& adj) { if ((int)adj[n].size() == 0) return n; int ret = 0; for (int i = 0; i < (int)adj[n].size(); i++) { ret = max(ret, dfs(adj[n][i], adj)); } return ret; } int main() { int n, m; cin >> n >> m; vector<vector<int> > rest(n + 1); for (int i = 0; i < m; i++) { int c, d; cin >> c >> d; rest[c].push_back(d); } vector<int> c, d; for (int i = 1; i <= n; i++) { int top = dfs(i, rest); if (top != i) { c.push_back(i); d.push_back(top); } } c.push_back(n + 1); d.push_back(n + 1); int ans = 0; int s = c[0], e = d[0]; for (int i = 1; i < (int)c.size(); i++) { if (c[i] <= e) { e = max(e, d[i]); } else { ans += e - s; s = c[i]; e = d[i]; } } ans = n + 1 + ans * 2; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int INF = 1e9; const double EPS = 1e-8; const double PI = 3.14159; int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; using namespace std; int main() { int N, m; cin >> N >> m; vector<pair<int, int> > list(m), tmp; for (int i = 0; i < (int)(m); i++) cin >> list[i].second >> list[i].first; sort((list).begin(), (list).end(), greater<pair<int, int> >()); list.push_back(pair<int, int>(-1, -1)); int a = list[0].first, b = list[0].second; for (int i = 1; i < m + 1; i++) { if (b <= list[i].first) { b = list[i].second; } else { tmp.push_back(pair<int, int>(a, b)); a = list[i].first, b = list[i].second; } } sort((tmp).begin(), (tmp).end()); int ans = N + 1; for (int i = 0; i < tmp.size(); i++) { ans += 2 * (tmp[i].first - tmp[i].second); } cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N, m, c, d; vector<pair<int, int> > V; cin >> N >> m; for (int i = 0; i < m; i++) { cin >> c >> d; V.push_back(make_pair(c, d)); } sort(V.begin(), V.end()); V.push_back(make_pair(1000000001, 1000000001)); for (int i = 0; i < V.size() - 1; i++) { if (V[i + 1].first <= V[i].second && V[i].second <= V[i + 1].second) { V[i].second = V[i + 1].second; V.erase(V.begin() + i + 1); i--; } } int ans = N + 1; for (int i = 0; i < V.size(); i++) { ans += 2 * (V[i].second - V[i].first); } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int intervalState(int a, int b, int c, int d) { if (a < c && b < c) return 0; else if (a > d && b > d) return 1; else if (a <= c && d <= b) return 2; else if (c < a && b < d) return 3; else if (a <= c && b < d) return 4; else if (c < a && d <= b) return 5; return -1; } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> v; pair<int, int> in[1005]; for (int i = 0; i < (m); i++) { int a, b; cin >> a >> b; in[i] = make_pair(a, -b); } sort(in, in + m); for (int i = 0; i < (m); i++) in[i].second *= -1; for (int i = 0; i < (m); i++) { if (v.empty()) v.emplace_back(in[i]); else { pair<int, int> &u = v.back(); int tmp = intervalState(in[i].first, in[i].second, u.first, u.second); switch (tmp) { case 0: case 1: v.emplace_back(in[i]); break; case 2: u.first = in[i].first; u.second = in[i].second; break; case 3: break; case 4: case 5: u.first = min(u.first, in[i].first); u.second = max(u.second, in[i].second); break; case -1: assert(0); } } } sort((v).begin(), (v).end()); int cur = 0, ans = 0; for (int i = 0; i < (v.size()); i++) { cout << v[i].first << ' ' << v[i].second << endl; ans += v[i].first - cur; ans += (v[i].second - v[i].first) * 3; cur = v[i].second; } ans += n + 1 - cur; cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1107110711071107; long long N, m; vector<pair<long long, long long> > d; long long dp[501][501][1001]; long long dfs(long long pre, long long now, long long n) { if (n == m) { return (now - pre + (N + 1) - pre); } if (dp[pre][now][n] >= 0) return dp[pre][now][n]; long long ret = dfs(pre, d[n].first, n + 1) + (d[n].first - now); ret = min(ret, dfs(d[n].second, d[n].first, n + 1) + (now - pre + d[n].first - pre)); return dp[pre][now][n] = ret; } signed main() { cin >> N >> m; fill_n(**dp, 501 * 501 * 1001, -1); for (long long i = 0; i < (m); i++) { long long c, b; cin >> c >> b; d.push_back(pair<long long, long long>(b, c)); } sort(d.begin(), d.end()); if (m == 0) cout << N + 1 << endl; else cout << dfs(d[0].second, d[0].first, 1) + d[0].first << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "["; for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { if (it != t.begin()) os << ","; os << *it; } os << "]"; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &t) { os << "{"; for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { if (it != t.begin()) os << ","; os << *it; } os << "}"; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } const int INF = 1 << 28; const double EPS = 1e-8; const int MOD = 1000000007; int n, m; int main() { ios::sync_with_stdio(false); cin >> n >> m; vector<pair<int, int> > segs; for (int i = 0; i < (int)(m); i++) { int l, r; cin >> l >> r; segs.emplace_back(l, r); } sort(segs.begin(), segs.end()); int ans = 0; int cur = 0; int back = 0; for (int i = 0; i < (int)(m); i++) { int l = segs[i].first; int r = segs[i].second; if (cur < l) { ans += (cur - back) * 2; back = l; } cur = r; } cout << n + 1 + ans + (cur - back) * 2 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Arrays; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import static java.lang.Math.*; public class Main { class Pair implements Comparable<Pair> { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair p) { return this.b - p.b; } } void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); if (m == 0) { System.out.println(n + 1); return; } Pair[] pair = new Pair[m]; for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); pair[i] = new Pair(a, b); } Arrays.sort(pair); // debug // for (int i = 0; i < m; i++) { // System.out.println(pair[i].a + " " + pair[i].b); // } // System.out.println(); Map<Integer, Integer> res = new TreeMap<Integer, Integer>(); int key = pair[0].b; int val = pair[0].a; for (int i = 1; i < m; i++) { if (pair[i].a <= key) { val = min(val, pair[i].a); key = max(key, pair[i].b); } else { // ?????????????????? if (res.containsKey(key)) { val = min(val, res.get(key)); } res.put(key, val); key = pair[i].b; val = pair[i].a; } } res.put(key, val); // debug // for (Integer k : res.keySet()) { // System.out.println(k + " " + res.get(k)); // } int count = 0; int pos = 0; for (Integer k : res.keySet()) { int back = res.get(k); count += ((k - pos) + (k - back) * 2); pos = k; } count += (n - pos + 1); System.out.println(count); } public static void main(String[] args) { new Main().run(); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; signed main() { int n, m; cin >> n >> m; vector<pair<int, int> > b(m); for (int i = 0; i < m; i++) cin >> b[i].first >> b[i].second; sort((b).begin(), (b).end()); vector<int> a(n + 2, 0); for (auto e : b) { a[e.first] += 1; a[e.second + 1] += -1; } for (int i = 1; i < n; i++) { a[i] += a[i - 1]; } bool flag = false; int cnt = 0; int ans = n + 1; for (auto e : a) { if (flag && !e) { flag = false; ans += 2 * (cnt - 1); cnt = 0; } else if (e) { cnt++; if (!flag) flag = true; } } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct node { int l; int r; } q[555]; bool cmp(node s1, node s2) { if (s1.l == s2.l) return s1.r < s2.r; return s1.l < s2.l; } int main() { int n, m; while (~scanf("%d%d", &n, &m)) { memset(q, 0, sizeof(q)); for (int i = 0; i < m; i++) { scanf("%d%d", &q[i].l, &q[i].r); } sort(q, q + m, cmp); int ans = q[0].r - q[0].l; for (int i = 1; i < m; i++) { int res = 0; res = max(q[i - 1].r, q[i].l); res = q[i].r - res; res = max(0, res); ans += res; } printf("%d\n", ans * 2 + n + 1); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.Integer.parseInt; /** * Shopping */ public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; String[] words; line = br.readLine(); int N, m; N = parseInt(line.substring(0, line.indexOf(' '))); m = parseInt(line.substring(line.indexOf(' ') + 1)); if (m == 0) { System.out.println(N + 1); return; } int[] shops = new int[N + 1]; for (int i = 0; i < m; i++) { line = br.readLine(); int c, d; c = parseInt(line.substring(0, line.indexOf(' '))); d = parseInt(line.substring(line.indexOf(' ') + 1)); shops[c]++; shops[d]--; } int zero = 0; for (int i = 1; i < shops.length; i++) { shops[i] += shops[i - 1]; if (shops[i] == 0) zero++; } System.out.println(zero + (N + 1 - zero) * 3); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const double EPS = 1e-9; static const double PI = acos(-1.0); int n, m; vector<pair<int, int> > constraint; bool used[1000]; bool intersect(pair<int, int> lhs, pair<int, int> rhs) { if (lhs.first <= rhs.first && rhs.first <= lhs.second) { return true; } if (rhs.first <= lhs.first && lhs.first <= rhs.second) { return true; } return false; } int main() { while (scanf("%d %d", &n, &m) > 0) { constraint.clear(); for (int i = 0; i < (int)(m); i++) { int x, y; scanf("%d %d", &x, &y); if (x > y) { continue; } constraint.push_back(make_pair(y, x)); } sort(constraint.begin(), constraint.end()); for (int i = 0; i < (int)(constraint.size()); i++) { swap(constraint[i].first, constraint[i].second); } memset((used), false, sizeof(used)); int ans = n + 1; for (int i = 0; i < (int)(constraint.size()); i++) { if (used[i]) { continue; } pair<int, int> range = constraint[i]; used[i] = true; for (int j = (i); j < (int)(constraint.size()); j++) { if (used[j]) { continue; } if (intersect(range, constraint[j])) { used[j] = true; range = make_pair(min(range.first, constraint[j].first), max(range.second, constraint[j].second)); } } ans += 2 * abs(range.second - range.first); } printf("%d\n", ans); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int n, m, c, d, imos[1001]; int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &c); scanf("%d", &d); imos[c--]++; imos[d--]--; } int ret = n + 2, sum = 0; for (int i = 0; i < n; i++) { sum += imos[i]; if (sum > 0) ret += 2; } printf("%d\n", ret); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { long long int N, M, ans = 0; cin >> N >> M; vector<int> data(N + 2); for (size_t i = 0; i < M; i++) { int a, b; cin >> a >> b; if (b > a) { data[a]++; data[b + 1]--; } } for (size_t i = 1; i < N + 2; i++) { data[i] += data[i - 1]; } ans += N + 1; long long int begin = 0, end; bool flag = 0, flag2 = 0; for (size_t i = 0; i < N + 2; i++) { if (data[i] > 0) { flag = 1; } if (data[i] == 0) { if (flag) { flag = 0; ans += (i - begin - 2) * 2; } begin = i; } } for (size_t i = 0; i < N + 2; i++) { cout << data[i] << " "; } cout << endl; cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int n, m, c, d, imos[1001]; int main() { scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < n; i++) { scanf("%d", &c); scanf("%d", &d); imos[c--]++; imos[d--]--; } int ret = n + 2, sum = 0; for (int i = 0; i < n; i++) { sum += imos[i]; if (sum > 0) ret += 2; } printf("%d\n", ret); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<int> vec[1010]; int a[1010], b[1010], vis[1010]; void dfs(int u) { for (int i = 0; i < vec[u].size(); i++) { int v = vec[u][i]; if (vis[v] == 0) { vis[v] = 1; dfs(v); a[u] = max(a[u], a[v]); } } } int main() { int n, m, u, v; while (scanf("%d%d", &n, &m) == 2) { for (int i = 1; i <= n; i++) vec[i].clear(); for (int i = 1; i <= m; i++) { scanf("%d%d", &u, &v); vec[u].push_back(v); } for (int i = 1; i <= n; i++) a[i] = i; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; i++) { if (vis[i] == 0) { vis[i] = 1; dfs(i); } } int ans = n + 1; int k = 1, k2 = 1, c = a[1], cc = a[1]; while (k <= n) { for (int i = k2; i <= c; i++) { cc = max(c, a[i]); } if (cc <= c) { ans = ans + (c - k) * 2; k = k2 = c + 1; c = cc = a[k]; } else { k2 = c; c = cc; } } cout << ans << endl; } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<vector> #include<set> #include<list> #include<queue> #include<cmath> #include<functional> #include<algorithm> #define INF (1<<29) #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; struct Range{ int s,e; Range(){} Range(int s,int e):s(s),e(e){} bool operator<(const Range &r)const{return e<r.e;} }; vector<Range> merge_range(vector<Range> &r){ vector<Range> res; sort(r.begin(),r.end()); for(int i=0;i<(int)r.size();i++){ int mi=r[i].s; while(!res.empty()&&r[i].s<=res.back().e){ mi=min(mi,res.back().s); res.pop_back(); } res.push_back(Range(mi,r[i].e)); } return res; } int main(){ int n,m; Range r[500]; cin>>n>>m; rep(i,m)cin>>r[i].s>>r[i].e; int ans=n+1; vector<Range> vr(merge_range(vector<Range>(r,r+m))); rep(i,vr.size()){ ans+=(vr[i].e-vr[i].s)*2; } cout<<ans<<endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const int INF = 1e9; const double EPS = 1e-8; const double PI = 3.14159; int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; using namespace std; int main() { int N, m; cin >> N >> m; vector<pair<int, int> > list(m), tmp; for (int i = 0; i < (int)(m); i++) cin >> list[i].second >> list[i].first; sort((list).begin(), (list).end(), greater<pair<int, int> >()); list.push_back(pair<int, int>(-1, -1)); int a = list[0].first, b = list[0].second; for (int i = 1; i < m + 1; i++) { if (b <= list[i].first) { b = list[i].second; } else { tmp.push_back(pair<int, int>(a, b)); a = list[i].first, b = list[i].second; } } tmp.push_back(pair<int, int>(0, 0)); tmp.push_back(pair<int, int>(N + 1, N + 1)); sort((tmp).begin(), (tmp).end()); int ans = 0; for (int i = 1; i < tmp.size(); i++) { ans += tmp[i].first - tmp[i - 1].second; ans += tmp[i].first - tmp[i].second; } cout << ans << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; const long long MOD = 1e9 + 7; long long sq(long long num) { return num * num; } long long mod_pow(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % MOD; long long res = sq(mod_pow(x, n / 2)); res %= MOD; if (n % 2 == 1) { res *= x; res %= MOD; } return res; } long long mod_add(long long a, long long b) { return (a + b) % MOD; } long long mod_sub(long long a, long long b) { return (a - b + MOD) % MOD; } long long mod_mul(long long a, long long b) { return a * b % MOD; } int n, m; vector<pair<long long, long long> > vp; long long dp[510][1010]; int main() { cin >> n >> m; if (m == 0) { cout << n + 1 << endl; return 0; } for (int i = 0; i < (m); i++) { long long c, d; cin >> c >> d; vp.push_back({c, d}); } sort((vp).begin(), (vp).end()); vector<pair<long long, long long> > vp2; long long d = -1; for (int i = 0; i < (vp.size()); i++) { if (d < vp[i].second) { d = vp[i].second; vp2.push_back(vp[i]); } } for (int i = 0; i < (510); i++) for (int j = 0; j < (1010); j++) dp[i][j] = INF; dp[0][0] = 0; int now = 0; for (int i = 0; i < (vp2.size()); i++) { long long ci = vp2[i].first; long long di = vp2[i].second; for (int j = (di); j < (n + 2); j++) { for (int k = (now); k < (n + 2); k++) { if (k < j) dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + (j - now) + (j - ci)); else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (ci - now)); } } now = ci; } d = vp.back().second; cout << dp[vp2.size()][d] + n + 1 - now << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; int main() { int N, m; cin >> N >> m; vector<int> backs(N, false); for (int i = 0; i < m; ++i) { int t, f; cin >> t >> f; t--; f--; for (int j = t; j < f; ++j) { backs[j] = true; } } int ans = 1 + N + accumulate(backs.begin(), backs.end(), 0); cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
public class Main{ public void run(java.io.InputStream in, java.io.PrintStream out){ java.util.Scanner sc = new java.util.Scanner(in); /*answer*/ int n, m; int[] c, d; int i, j, k, tmp, ans, cmp; n = sc.nextInt(); m = sc.nextInt(); c = new int[m]; d = new int[m]; ans = 0; cmp = 0; for(i = 0;i < m;i++){ c[i] = sc.nextInt(); d[i] = sc.nextInt(); } sc.close(); for(i = 0;i < m;i++){ for(j = 0;j < (m - i - 1);j++){ if(c[j] > c[j + 1]){ tmp = c[j]; c[j] = c[j + 1]; c[j + 1] = tmp; tmp = d[j]; d[j] = d[j + 1]; d[j + 1] = tmp; }else if(c[j] == c[j + 1] && d[j] > d[j + 1]){ tmp = c[j]; c[j] = c[j + 1]; c[j + 1] = tmp; tmp = d[j]; d[j] = d[j + 1]; d[j + 1] = tmp; } } } for(j = 0;j < m;j++){ tmp = j; for(k = j;k < m;k++){ if(c[k] > d[j] || d[j] > d[k]){ d[j] = d[k - 1]; j = k - 1; cmp = 0; break; } cmp = 1; } ans = ans + (d[k - 1] - c[tmp]) * 2; if(cmp == 1)break; } ans += (n + 1); System.out.println(ans); /*fin*/ } public static void main(String[] args){ (new Main()).run(System.in, System.out); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; long long int res = 0; int main() { int N, m; cin >> N >> m; int t = 1; for (int i = 1; i <= m; i++) { int c, d; cin >> c >> d; q.push(make_pair(c, d)); } while (!q.empty()) { int c1 = q.top().first; int d1 = q.top().second; q.pop(); if (!q.empty()) { int c2 = q.top().first; int d2 = q.top().second; if (d1 >= c2) { q.pop(); q.push(make_pair(c1, d2)); } else { res += 2 * (d1 - c1); } } else res += 2 * (d1 - c1); } cout << res + N + 1 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector<pair<int, int> > ps(M); for (int i = (0); i < (M); ++i) cin >> ps[i].first >> ps[i].second; sort((ps).begin(), (ps).end()); for (int i = 0; i + 1 < int((ps).size()); ++i) { if (ps[i + 1].first <= ps[i].second) { ps[i].second = ps[i + 1].second; ps.erase(ps.begin() + i + 1); --i; } } int ans = 0, l = 0; for (int i = 0; i < int((ps).size()); ++i) { ans += ps[i].second - l + 2 * (ps[i].second - ps[i].first); l = ps[i].second; } ans += N + 1 - l; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
#include <bits/stdc++.h> int main() { int i, j; int d[1001]; for (i = 0; i <= 1000; ++i) { d[i] = 0; } int n, m; scanf("%d", &n); for (i = 0; i <= n; ++i) { d[i] = 1; } scanf("%d", &m); int a, b; for (i = 0; i < m; ++i) { scanf("%d", &a); scanf("%d", &b); for (j = a; j < b; ++j) { d[j] = 3; } } int sum = 0; for (i = 0; i <= n; ++i) { sum += d[i]; } printf("%d", sum); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main(void) { int N, M; cin >> N >> M; vector<pair<int, int>> R(M); for (auto &i : R) cin >> i.first >> i.second; sort(R.begin(), R.end()); int ans = 0, now = 0; int c, d; for (auto i = R.begin(); i != R.end();) { c = i->first; d = i->second; for (i++; i != R.end(); i++) { if (i->first > d) break; d = i->second; } ans += (d - now); ans += (d - c); now = c; } ans += (N + 1 - now); cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c, d, l, r, flag, sum; int V[1001] = {0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> c >> d; V[c] = max(V[c], d); } l = r = -1; flag = sum = 0; for (int i = 0; i <= n; i++) { if (r == i) sum += 3 * (r - l) + 1, flag = 0; else if (flag && V[i] != 0) r = max(r, V[i]); else if (V[i] != 0 && !flag) l = i, r = V[i], flag = 1; else if (!flag) sum++; } cout << sum << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; static const int INF = 1e9; static const double PI = acos(-1.0); static const double EPS = 1e-10; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline int BITS_COUNT(unsigned long long int b) { int c = 0; while (b != 0) { c += (b & 1); b >>= 1; } return c; } inline int MSB(unsigned long long int b) { int c = 0; while (b != 0) { ++c; b >>= 1; } return c - 1; } inline int MAKE_MASK(unsigned long long int upper, unsigned long long int lower) { assert(lower < 64 && upper < 64 && lower <= upper); return ((assert((!numeric_limits<typeof(upper)>::is_signed)), assert(upper < 64), (1ULL << (upper))) - 1) ^ ((assert((!numeric_limits<typeof(lower)>::is_signed)), assert(lower < 64), (1ULL << (lower))) - 1); } template <typename T> ostream& operator<<(ostream& s, const complex<T>& d) { return s << "(" << d.real() << ", " << d.imag() << ")"; } template <typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& d) { return s << "(" << d.first << ", " << d.second << ")"; } template <typename T> ostream& operator<<(ostream& s, const vector<T>& d) { int len = d.size(); for (typeof(len) i = (0); i < (len); ++i) { s << d[i]; if (i < len - 1) s << "\t"; } return s; } template <typename T> ostream& operator<<(ostream& s, const vector<vector<T> >& d) { int len = d.size(); for (typeof(len) i = (0); i < (len); ++i) { s << d[i] << endl; } return s; } template <typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) { s << "{" << endl; for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) { s << "\t" << (*itr).first << " : " << (*itr).second << endl; } s << "}" << endl; return s; } inline double now() { struct timeval tv; gettimeofday(&tv, NULL); return (static_cast<double>(tv.tv_sec) + static_cast<double>(tv.tv_usec) * 1e-6); } inline vector<string> split(string s, char delimiter) { vector<string> v; string t; for (typeof(s.length()) i = (0); i < (s.length()); ++i) { if (s[i] == delimiter) v.push_back(t), t = ""; else t += s[i]; } v.push_back(t); return v; } inline string join(vector<string> s, string j) { string t; for (typeof(s.size()) i = (0); i < (s.size()); ++i) { t += s[i] + j; } return t; } enum { UP, RIGHT, DOWN, LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT, UP_LEFT }; complex<int> dydx4[4] = {complex<int>(-1, 0), complex<int>(0, 1), complex<int>(1, 0), complex<int>(0, -1)}; complex<int> dydx8[8] = {complex<int>(-1, 0), complex<int>(0, 1), complex<int>(1, 0), complex<int>(0, -1), complex<int>(-1, 1), complex<int>(1, 1), complex<int>(1, -1), complex<int>(-1, -1)}; bool in_field(int H, int W, complex<int> p) { return (0 <= p.real() && p.real() < H) && (0 <= p.imag() && p.imag() < W); } inline void input(string filename) { freopen(filename.c_str(), "r", stdin); } inline void output(string filename) { freopen(filename.c_str(), "w", stdout); } bool opt_debug = false; int main(int argc, char** argv) { std::ios_base::sync_with_stdio(false); int __c; while ((__c = getopt(argc, argv, "d")) != -1) { switch (__c) { case 'd': opt_debug = true; break; default: abort(); } } int N, m; cin >> N >> m; vector<int> dependencies(N + 1, 0); for (typeof(m) i = (0); i < (m); ++i) { int c, d; cin >> c >> d; dependencies[c] = d; } if (opt_debug) { cerr << " [L" << 282 << "] " << "dependencies" << " = " << (dependencies) << endl; }; int ans = 0; int back = INF; map<int, int> backto; for (typeof(N + 1) i = (1); i < (N + 1); ++i) { ans++; if (((backto).find(i) != (backto).end())) { backto.erase(i); if (backto.size() == 0) { ans += (i - back) * 2; back = INF; } } if (dependencies[i] != 0) { if (dependencies[i] > i) { if (((backto).find(dependencies[i]) != (backto).end())) { backto[dependencies[i]] = min(backto[dependencies[i]], i); } else { backto[dependencies[i]] = i; } back = min(back, i); } } } cout << ans + 1 << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const double EPS = 1e-9; const int MOD = 1000000007; int N, M; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; vector<pair<int, int>> v; for (int i = 0; i < (M); i++) { int c, d; cin >> c >> d; v.push_back(make_pair(c, d)); } sort(v.begin(), v.end()); int ans = N + 1; int i = 0; while (i < M) { int s = i; int m = v[i].second; while (i + 1 < M && v[i + 1].first <= m) { i++; m = max(m, v[i].second); } ans += (v[i].second - v[s].first) * 2; i++; } cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int n, q, a, b; int x[100000], sum; int main() { cin >> n >> q; for (int i = 0; i < q; i++) { cin >> a >> b; for (int j = a; j < b; j++) { x[j] = 1; } } for (int i = 0; i < n; i++) { sum += 1 + x[i] * 2; } cout << sum << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1107110711071107; long long N, m; vector<pair<long long, long long> > d; unordered_map<long long, long long> dp[1001][1001]; long long dfs(long long pre, long long now, long long n) { if (n == m) { return (now - pre + (N + 1) - pre); } if (dp[pre][now][n] > 0) return dp[pre][now][n]; long long ret = dfs(pre, d[n].first, n + 1) + (d[n].first - now); ret = min(ret, dfs(d[n].second, d[n].first, n + 1) + (now - pre + d[n].first - pre)); return dp[pre][now][n] = ret; } signed main() { cin >> N >> m; for (long long i = 0; i < (m); i++) { long long c, b; cin >> c >> b; d.push_back(pair<long long, long long>(b, c)); } sort(d.begin(), d.end()); if (m == 0) cout << N + 1 << endl; else cout << dfs(d[0].second, d[0].first, 1) + d[0].first << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000; const int MAX_M = 500; pair<int, int> rvs[MAX_M]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) cin >> rvs[i].first >> rvs[i].second; sort(rvs, rvs + m); int sum = 0, pci = -1, pdi = -1; for (int i = 0; i < m; i++) { int &ci = rvs[i].first, &di = rvs[i].second; if (pdi >= ci) pdi = di; else { sum += pdi - pci; pci = ci, pdi = di; } } sum += pdi - pci; printf("%d\n", n + 1 + sum * 2); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q; long long int res = 0; int main() { int N, m; cin >> N >> m; int t = 1; for (int i = 1; i <= m; i++) { int c, d; cin >> c >> d; q.push(make_pair(c, d)); } while (!q.empty()) { int c1 = q.top().first; int d1 = q.top().second; q.pop(); if (!q.empty()) { int c2 = q.top().first; int d2 = q.top().second; if (d1 >= c2) { q.pop(); q.push(make_pair(c1, d2)); } else { res += 2 * (d1 - c1); } } else res += 2 * (d1 - c1); } cout << res + N + 1; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.Arrays; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import static java.lang.Math.*; public class Main { class Pair implements Comparable<Pair> { int a; int b; public Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair p) { return this.b - p.b; } } void run() { // input Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); if (m == 0) { System.out.println(n + 1); return; } Pair[] pair = new Pair[m]; for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); pair[i] = new Pair(a, b); } Arrays.sort(pair); // debug // for (int i = 0; i < m; i++) { // System.out.println(pair[i].a + " " + pair[i].b); // } // System.out.println(); Map<Integer, Integer> res = new TreeMap<Integer, Integer>(); int key = pair[0].b; int val = pair[0].a; for (int i = 1; i < m; i++) { if (pair[i].a <= key) { val = min(val, pair[i].a); key = max(key, pair[i].b); } else { // ?????????????????? if (res.containsKey(key)) { val = min(val, res.get(key)); } res.put(key, val); key = pair[i].b; val = pair[i].a; } } res.put(key, val); // debug // for (Integer k : res.keySet()) { // System.out.println(k + " " + res.get(k)); // } int count = 0; int pos = 0; for (Integer k : res.keySet()) { int back = res.get(k); count += ((k - pos) + (k - back) * 2); pos = k; } count += (n - pos + 1); System.out.println(count); } void run1() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); Pair[] pair = new Pair[m]; for (int i = 0; i < m; i++) { int a = sc.nextInt(); int b = sc.nextInt(); pair[i] = new Pair(a, b); } Arrays.sort(pair); int[] mark = new int[n]; for (int i = 0; i < m; i++) { int s = pair[i].b - 1; int e = pair[i].a - 1; for (int j = e; j <= s; j++) { mark[j] = 1; } } int count = 0; int s = 0; for (int i = 0; i < n; i++) { if (mark[i] == 0) { count += s; } else { s++; } } } public static void main(String[] args) { new Main().run(); } }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
a[999],m,n,c;main(d){ for(scanf("%d%d",&n,&m);m--;)for(scanf("%d%d",&c,&d);c<d;c++)a[c]=1; for(c=d=0;c<n;c++)d+=a[c]*2; m=!printf("%d\n",d+n+1); }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int> > s; for (int(i) = 0; (i) < (int)(m); ++(i)) { int c, d; scanf(" %d %d", &c, &d); if (c < d) s.push_back(pair<int, int>(c, d)); } sort((s).begin(), (s).end()); int ans = n + 1; int back = s[0].first; if (m > 0) { for (int(i) = 0; (i) < (int)(m - 1); ++(i)) { if (s[i].second < s[i + 1].first) { ans += 2 * (s[i].second - back); back = s[i + 1].first; } } ans += 2 * (s[m - 1].second - back); } printf("%d\n", ans); return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int dfs(int n, vector<vector<int> >& adj) { if ((int)adj[n].size() == 0) return n; int ret = 0; for (int i = 0; i < (int)adj[n].size(); i++) { ret = max(ret, dfs(adj[n][i], adj)); } return ret; } int main() { int n, m; cin >> n >> m; vector<vector<int> > rest(n + 1); for (int i = 0; i < m; i++) { int c, d; cin >> c >> d; rest[c].push_back(d); } vector<int> c, d; for (int i = 1; i <= n; i++) { int top = dfs(i, rest); if (top != i) { c.push_back(i); d.push_back(top); } } c.push_back(n + 1); d.push_back(n + 1); int ans = 0; int s = c[0], e = d[0]; for (int i = 1; i < m + 1; i++) { if (c[i] <= e) { e = max(e, d[i]); } else { ans += e - s; s = c[i]; e = d[i]; } } ans = n + 1 + ans * 2; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int dfs(int n, vector<vector<int> >& adj) { if ((int)adj[n].size() == 0) return n; int ret = 0; for (int i = 0; i < (int)adj[n].size(); i++) { ret = max(ret, dfs(adj[n][i], adj)); } return ret; } int main() { int n, m; cin >> n >> m; vector<vector<int> > dep(n + 1); for (int i = 0; i < m; i++) { int c, d; cin >> c >> d; dep[c].push_back(d); } vector<int> c, d; for (int i = 1; i <= n; i++) { int top = dfs(i, dep); if (top != i) { c.push_back(i); d.push_back(top); } } c.push_back(n + 1); d.push_back(n + 1); int ans = 0; int s = c[0], e = d[0]; for (int i = 1; i < m + 1; i++) { if (c[i] <= e) { e = max(e, d[i]); } else { ans += e - s; s = c[i]; e = d[i]; } } ans = n + 1 + ans * 2; cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
a[999],n,m,c;main(d){ for(scanf("%d%d",&n,&m);m--;)for(scanf("%d%d",&c,&d);c<d;c++)a[c]=1; for(c=d=0;c<n;c++)d+=a[c]*2; m=!printf("%d\n",d+n+1); }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct ioi { int l, r; } seg[510]; int n, m; bool intersect(ioi a, ioi b) { if (a.l > b.l) swap(a, b); if (b.l <= a.r) return true; else return false; } ioi combine(ioi a, ioi b) { a.l = min(a.l, b.l); a.r = max(a.r, b.r); return a; } int main() { cin >> n >> m; for (int i = 1; i <= m; i++) cin >> seg[i].l >> seg[i].r; long long res = n + 1; sort(seg + 1, seg + m + 1, [](ioi a, ioi b) { return (a.l < b.l or (a.l == b.l and a.r > b.r)); }); ioi current_segment = seg[1]; for (int i = 1; i <= m; i++) { if (intersect(seg[i], current_segment)) { current_segment = combine(current_segment, seg[i]); } else { res += 2 * (current_segment.r - current_segment.l); current_segment = seg[i]; } } res += 2 * (current_segment.r - current_segment.l); cout << res << "\n"; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N, m; cin >> N >> m; vector<int> shop(N); for (int i = 0; i < (int)(m); ++i) { int c, d; cin >> c >> d; shop[c - 1]++; shop[d - 1]--; } int res = N + 1; int cnt = 0; int start = -1; for (int i = 0; i < (int)(N); ++i) { if (shop[i] == 0) continue; cnt += shop[i]; fprintf(stderr, "%d %d\n", i, shop[i]); if (start == -1) start = i; if (cnt == 0) { res += (i - start) * 2; start = -1; } } cout << res << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> const unsigned long long inf = 1LL << 61; const double eps = 1e-5; using namespace std; struct node { int s, e; } a[10000 + 5]; bool cmp(node a, node b) { return a.s < b.s; } vector<node> v; int main() { int n, m; while (cin >> n >> m) { for (int i = 0; i < m; i++) cin >> a[i].s >> a[i].e; v.clear(); sort(a, a + m, cmp); node u; u.s = a[0].s; u.e = a[0].e; int mark = 0; for (int i = 1; i < m; i++) { if (a[i].s <= a[i - 1].e && a[i].e >= a[i - 1].e) { u.e = a[i].e; mark++; } else if (a[i].s > a[i - 1].e) { v.push_back(u); u.s = a[i].s; u.e = a[i].e; mark++; } } if (mark < m) { v.push_back(u); } int ans = 0; for (int i = 0; i < v.size(); i++) { ans += 2 * (v[i].e - v[i].s); } ans += n + 1; printf("%d\n", ans); } return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct rest { int start, end; inline void set(int a, int b) { start = a; end = b; } bool operator<(const rest &a) const { return end < a.end; } } rests[600]; int n, m, restlen; bool exist[600]; int main() { int a, b; while (scanf("%d%d", &n, &m) == 2) { restlen = 0; memset(exist, true, sizeof(exist)); for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); if (a < b) { rests[restlen].start = a; rests[restlen].end = b; restlen++; } } sort(rests, rests + restlen); for (int i = 0; i < m; i++) { for (int j = i - 1; j >= 0; j--) if (exist[j] && rests[j].end >= rests[i].start) { printf("%d %d\n", rests[i].end, rests[j].end); rests[i].start = min(rests[i].start, rests[j].start); exist[j] = false; } } int ans = n + 1; for (int i = 0; i < m; i++) if (exist[i]) ans += (rests[i].end - rests[i].start) << 1; printf("%d\n", ans); } return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; const long long MOD = 1e9 + 7; long long sq(long long num) { return num * num; } long long mod_pow(long long x, long long n) { if (n == 0) return 1; if (n == 1) return x % MOD; long long res = sq(mod_pow(x, n / 2)); res %= MOD; if (n % 2 == 1) { res *= x; res %= MOD; } return res; } long long mod_add(long long a, long long b) { return (a + b) % MOD; } long long mod_sub(long long a, long long b) { return (a - b + MOD) % MOD; } long long mod_mul(long long a, long long b) { return a * b % MOD; } int n, m; vector<pair<long long, long long> > vp; long long dp[510][1010]; int main() { cin >> n >> m; if (m == 0) { cout << n + 1 << endl; return 0; } for (int i = 0; i < (m); i++) { long long c, d; cin >> c >> d; vp.push_back({c, d}); } sort((vp).begin(), (vp).end()); for (int i = 0; i < (510); i++) for (int j = 0; j < (1010); j++) dp[i][j] = INF; dp[0][0] = 0; int now = 0; for (int i = 0; i < (m); i++) { long long ci = vp[i].first; long long di = vp[i].second; for (int j = (di); j < (n + 1); j++) { for (int k = (now); k < (n + 1); k++) { if (k < j) dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + (j - now) + (j - ci)); else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (ci - now)); } } now = ci; } long long d = vp.back().second; cout << dp[m][d] + n + 1 - now << endl; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int N, m; cin >> N >> m; vector<bool> select(m, true); vector<pair<int, int>> cd(m); for (int i = 0; i < m; ++i) cin >> cd[i].first >> cd[i].second; sort(cd.begin(), cd.end()); for (int i = 0; i < m; ++i) { if (cd[i].second <= cd[i].first) select[i] = false; } for (int i = 0; i < m; ++i) { bool isIN = false; for (int j = i + 1; j < m; ++j) { if (cd[j].first <= cd[i].first && cd[i].second <= cd[j].second) { isIN = true; break; } } if (isIN) select[i] = false; } for (int i = 0; i < m; ++i) { if (!select[i]) continue; for (int j = i + 1; j < m; ++j) { if (!select[j]) continue; if (cd[i].first <= cd[j].first && cd[j].first < cd[i].second) { select[j] = false; cd[i].second = cd[j].second; } } } int ans = N + 1; for (int i = 0; i < m; ++i) if (select[i]) ans += 2 * (cd[i].second - cd[i].first); cout << ans << endl; return 0; }
p00926 Shopping
Example Input 10 3 3 7 8 9 2 5 Output 23
{ "input": [ "10 3\n3 7\n8 9\n2 5" ], "output": [ "23" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VVI = vector<VI>; using PII = pair<ll, ll>; const ll LLINF = (1LL << 60); const ll INF = (1LL << 30); const ll MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; } template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ',' << a.second << ')'; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &a) { out << '['; for (ll i = (ll)0; i < (ll)a.size(); ++i) { out << a[i]; if (i != a.size() - 1) out << ','; } out << ']'; return out; } ll dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; signed main(void) { ll n, m; cin >> n >> m; vector<PII> v; for (ll i = (ll)0; i < (ll)m; ++i) { ll c, d; cin >> c >> d; if (c < d) v.push_back({d, c}); } sort(v.begin(), v.end()); if (v.size() == 0) { cout << n + 1 << endl; return 0; } ll ret = n + 1; ll l = v[0].second, r = v[0].first; for (ll i = (ll)1; i < (ll)v.size(); ++i) { if (l <= v[i].second && v[i].second <= r) { r = v[i].first; } else { ret += (r - l) * 2; l = v[i].second, r = v[i].first; } } ret += (r - l) * 2; cout << ret << endl; return 0; }