結果

問題 No.580 旅館の予約計画
ユーザー marc2825marc2825
提出日時 2022-12-16 17:13:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 8,543 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 165,312 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:51:15
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#ifndef ONLINE_JUDGE
//#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <string>
#include <bitset>
#include <functional>
#include <list>
#include <deque>
#include <utility>
#include <numeric>
#include <complex>
#include <cctype>
#include <climits>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <random>
#include <fstream>
#include <chrono>

using namespace std;

//#define int long long
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pcc = pair<char, char>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
 
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 (b < a) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repback(i, n) for (ll i = n-1; i >= 0; i--)
#define REP(i, a, b) for (ll i = a; i < ll(b); i++)
#define REPBACK(i, a, b) for (ll i = a-1; i >= ll(b); i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS)
#ifndef ONLINE_JUDGE
#define debug(x) cout << "debug:" << (x) << endl
#define debug2(x, y) cout << "debug:" << (x) << " " << (y) << endl
#define debug3(x, y, z) cout << "debug:" << (x) << " " << (y) << " " << (z) << endl
#define debug4(x, y, z, w) cout << "debug:" << (x) << " " << (y) << " " << (z) << (w) << endl
#define debuga debug("a")
#else
#define debug(x) void(0)
#define debug2(x, y) void(0)
#define debug3(x, y, z) void(0)
#define debug4(x, y, z, w) void(0)
#define debuga void(0)
#endif
#define YESNO(bool) if(bool){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
#define yesno(bool) if(bool){cout<<"yes"<<'\n';}else{cout<<"no"<<'\n';}
#define YesNo(bool) if(bool){cout<<"Yes"<<'\n';}else{cout<<"No"<<'\n';}
 
static const double pi = acos(-1.0);
const long long INFL = pow(10,18);
const long long INFLMAX = 9223372036854775807;
const int INF = pow(10,9);
const int INFMAX = 2147483647;
const int mod1 = 1000000007;
const int mod2 = 998244353;
const vi dx1 = {1,0,-1,0};
const vi dy1 = {0,1,0,-1};
const vi dx2 = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const vi dy2 = {1, 1, 0, -1, -1, -1, 0, 1, 1};

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	os << "[";
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "]";
	return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
	os << "{";
	for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
		os << "(" << itr->first << ", " << itr->second << ")";
		itr++;
		if(itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
	os << "{";
	for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
		os << *itr;
		++itr;
		if(itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

 
class Point{
    public:
        double x, y;
 
        Point(double x = 0, double y = 0): x(x), y(y) {}
 
        
        Point operator + (Point p) {return Point(x + p.x, y + p.y); }
        Point operator - (Point p) {return Point(x - p.x, y - p.y); }
        Point operator * (double a) {return Point(a * x, a * y); }
        Point operator / (double a) {return Point(x / a, y / a); }
        
 
        double norm() {return x * x + y * y; }
        double abs() {return sqrt(norm()); }
 
 
        bool operator == (const Point &p) const{
            return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
        }
 
        bool operator < (const Point &p) const{
            return x != p.x ? x < p.x : y < p.y;
        }
};

double dot(Point a, Point b){return a.x * b.x + a.y * b.y;}
double cross(Point a, Point b){return a.x * b.y - a.y * b.x;}

struct Edge{
    ll to, cost;
 
    Edge(ll to = 0, ll cost = 0) : to(to), cost(cost) {}
 
};
 
using Graph = vector<vector<Edge> >;
 
//x^n % mod を計算
ll mpow(ll x, ll n, ll mod){
    x %= mod;
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}
 
//10進数(long long) → 2進数(string)への変換
string toBinary(ll n)
{
    if(n == 0) return "0";

    string ret;
    while (n != 0){
        ret += ( n % 2 == 0 ? '0' : '1' );
        n /= 2;
    }
    reverse(ret.begin(), ret.end());
 
    return ret;
}
 
//2進数(string) → 10進数(long long)への変換
ll toDecimal(string S){
    ll ret = 0;
    for(int i = 0; i < S.size(); i++){
        ret *= 2;
        if(S[i] == '1') ret += 1;
    }
 
    return ret;
}
 
 
ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
 
    if(a%b == 0) return b;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}

//拡張ユークリッドの互除法
//ax + by = gcd(a, b) を満たす (x, y) が格納される (返り値: a と b の最大公約数)
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    // a = a/b * b + a % b を上式に再帰的に適用
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x; 
    return d;
}

// 行列同士の積
vvll matrix_prod(vvll &A, vvll &B){
    // Aは i * k , Bは k * j の行列 -> 積で i * j の行列を返す
    assert(A[0].size() == B.size());
    int r = A.size();
    int c = B[0].size();

    vvll ret(r, vll(c,0));
    rep(i,r){
        rep(j,c){
            rep(k,B.size()){
                ret[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    return ret;
}


//Union-Find
struct unionfind{
    vector<int> par, siz;
 
    //初期化
    unionfind(int n) : par(n, -1), siz(n, 1) {}
 
    //根を求める
    int root(int x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }
 
    //xとyの根(グループ)が一致するかどうか
    bool issame(int x, int y){
        return root(x) == root(y);
    }
 
    //xとyのグループの併合
    bool unite(int x, int y){
        x = root(x); y = root(y);
 
        if (x == y) return false;
 
        if (siz[x] < siz[y]) swap(x,y);
 
        par[y] = x;
        siz[x] += siz[y];
        return true;
    }
 
    //xを含むグループのサイズ
    int size(int x){
        return siz[root(x)];
    }
};


signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    //cout << fixed << setprecision(10);
	
    int n,m; cin >> n >> m;
    vpii es(m);
    rep(i,m){
        int time = 0;
        int d; cin >> d;
        time += 24 * 60 * d;
        rep(i,5){
            char c; cin >> c;
            if(i == 2) continue;
            else if(i == 0) time += 10*60*(c-'0');
            else if(i == 1) time += 60 * (c-'0');
            else if(i == 3) time += 10 * (c - '0');
            else time += (c - '0');
        }
        es[i].second = time;

        time = 0;
        cin >> d;
        time += 24 * 60 * d;
        rep(i,5){
            char c; cin >> c;
            if(i == 2) continue;
            else if(i == 0) time += 10*60*(c-'0');
            else if(i == 1) time += 60 * (c-'0');
            else if(i == 3) time += 10 * (c - '0');
            else time += (c - '0');
        }
        es[i].first = time;
    }
    sort(all(es));
    
    multiset<int> st;
    rep(i,n) st.insert(-1);

    int ans = 0;
    rep(i,m){
        int nowstart = es[i].second;
        auto it = st.upper_bound(nowstart-1);
        if(it == st.begin()) continue;
        it--;
        ans++;
        st.erase(it);
        st.insert(es[i].first);
    }

    cout << ans << endl;

}
0